From Python 2.6 - with the string.format method :
"{0:b}".format(0x1234)
in particular, you can use the registration, so that several prints of different numbers still line up:
"{0:16b}".format(0x1234)
and leave a space with leading 0, not spaces:
"{0:016b}".format(0x1234)
From Python 3.6 - with f-strings :
The same three examples with f-lines will be:
f"{0x1234:b}" f"{0x1234:16b}" f"{0x1234:016b}"
Finlay McWalter Sep 22 '13 at 16:26 2013-09-22 16:26
source share