python decimal number into 8 bit binary

34

python decimal number into 8 bit binary -

>>> print(bin(160))  # This version gives the 0b prefix for binary numbers.
0b10100000
>>> print(format(160,'08b'))  # This specifies leading 0, 8 digits, binary.
10100000
>>> print('{:08b}'.format(160)) # Another way to format.
10100000
>>> print(f'{160:08b}')  # Python 3.6+ new f-string format.
10100000

Comments

Submit
0 Comments