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 let Python know that this is a binary number and not some integer. And that is ok within Python but what is considered safe practise here if you want to communicate with the outside world? This might be a silly example but online converters for instance do not recognise the above binary.
Would simply removing b
always do the trick? Because I seem to be running into problems trying to code the Ascii85 encoder/decoder where concatenations of binary numbers take place. You can take a look at this example here.
My code is this case produces the following:
ch = 'Man '
list_ = [ord(x) for x in ch] # [77, 97, 110, 32]
binary_repr = ''.join(bin(x) for x in list_) # 0b10011010b11000010b11011100b100000
# When it should be 01001101011000010110111000100000
Notice that simply replacing the b
with nothing doesn't quite cut it here. This is probably some dumm mistake but can someone clear things up for me?