>>> '{0:08b}'.format(6)
00000110
Just to explain the parts of the formatting string:
{}places a variable into a string0takes the variable at argument position 0:adds formatting options for this variable (otherwise it would represent decimal6)08formats the number to eight digits zero-padded on the leftbconverts the number to its binary representation
ref. http://stackoverflow.com/questions/10411085/converting-integer-to-binary-in-python
沒有留言:
張貼留言