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?
- If
xis already a string, then''.join(map(str, x))is completely unnecessaryTerryA– TerryA2018-05-12 11:00:30 +00:00CommentedMay 12, 2018 at 11:00
1 Answer1
is this what you want? am I missing something?
>>> binary_string = '1011'>>> binary_integer = int(binary_string, 2)>>> binary_integer11>>> 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.
Sign up to request clarification or add additional context in comments.
1 Comment
zgebac26
Hey Ali, I have a similar problem, and the problem with your solution is that it is still a string. I suppose the initial problem was (like mine), how to transform that binary string to a binary integer. Any ideas?
Explore related questions
See similar questions with these tags.

