Topic: program that inverts strings of binary numbers.......help needed
Write a program that inverts the string of binary numbers. Invert the 0’s to 1’s and 1’s to ‘0
e.g. binary=”010101011001100011”
output: “101010100110011100”
Community of Helpful Python Developers. Our Python forum is filled with tips, tricks and developers waiting to help.
You are not logged in. Please login or register.
Write a program that inverts the string of binary numbers. Invert the 0’s to 1’s and 1’s to ‘0
e.g. binary=”010101011001100011”
output: “101010100110011100”
>>> s = '010101011001100011'
>>> s.replace('0', '*').replace('1', '0').replace('*', '1')
'101010100110011100'
>>>>>> s.translate(str.maketrans('01', '10'))
'101010100110011100'
>>>Last edited by struct.h (January 27, 2012 05:15)