integer to binary 0-padded

jmfauth wxjmfauth at gmail.com
Sat Jun 18 02:14:09 EDT 2011


>>> '{:+#0{}b}'.format(255, 1 + 2 + 16)
+0b0000000011111111
>>> '{:+#0{}b}'.format(-255, 1 + 2 + 16)
-0b0000000011111111
>>>
>>> eval('{:+#0{}b}'.format(255, 1 + 2 + 16))
255
>>> eval('{:+#0{}b}'.format(-255, 1 + 2 + 16))
-255
>>>

jmf



More information about the Python-list mailing list