What does the "b" stand for in the output of bin(30): "0b11110". Is there any way I can get rid of this "b". How can I get the output of bin() to always return a standard 8 digit output?
Thank you,
What does the "b" stand for in the output of bin(30): "0b11110". Is there any way I can get rid of this "b". How can I get the output of bin() to always return a standard 8 digit output?
Thank you,
0b is like 0x - it indicates the number is formatted in binary (0x indicates the number is in hex).
See How do you express binary literals in python?
See http://docs.python.org/dev/whatsnew/2.6.html#pep-3127-integer-literal-support-and-syntax
To strip off the 0b it's easiest to use string slicing: bin(30)[2:]
And similarly for format to 8 characters wide:
('00000000'+bin(30)[2:])[-8:]
Alternatively you can use the string formatter (in 2.6+) to do it all in one step:
"{0:08b}".format(30)