Skip to content Skip to sidebar Skip to footer

Concatenate Numbers In Binary

When converting a number in binary in Python what you get is the following: b = bin(77) print(b) # 0b1001101 When I was expecting 01001101. I am guessing that the b is there to l

Solution 1:

>>>format(b, '08b') 

Where b is your number and '08b' is the number of bit you want to use representing your number, if the parameter is #08b instead of 08b, you get the 0b in front of the number.

use format in every further operation and you should be good!

Solution 2:

Doesn't

str(b)[2:]

do the job?

But you'll maybe better do:

"{0:b}".format(77)

Post a Comment for "Concatenate Numbers In Binary"