I have a program in which I need to convert for example a variable containing the string '01000100'
to 0b01000100
so I can decode it to the corresponding symbol, in this case, the letter 'D'
using the built in chr()
function. How is it possible to do this conversion or is there an easier way to convert the string to the corresponding symbol?
CodePudding user response:
You don't need to add the 0b
, you just need to call the int
constructor appropriately, passing a second argument of 2
so it knows the input is in base 2.
chr(int('01000100', 2))