I need to convert binary string e.g. 1011 to binary number in python. I used this code but it gives me one more 0 to end
bin(int(''.join(map(str, x)), 2) << 1)
x is string which I want to convert. Could someone help me how to do it?
is this what you want? am I missing something?
>>> binary_string = '1011'
>>> binary_integer = int(binary_string, 2)
>>> binary_integer
11
>>> binary_literal = bin(binary_integer)
>>> binary_literal
'0b1011'
If this is not what you want, can you elaborate? what is the input, and what is the desired output? I hope i could help.
xis already a string, then''.join(map(str, x))is completely unnecessary