Back
I tried the below code to convert an integer to binary
>>> bin(6) '0b110'
>>> bin(6)
'0b110'
I used the below code to erase the '0b'
>>> bin(6)[2:]'110'
>>> bin(6)[2:]
'110'
What I should do to show 6 as 00000110 instead of 110?
Try the following code:
>>> '{0:08b}'.format(6)'00000110'
>>> '{0:08b}'.format(6)
'00000110'
In case if you're using python version 3.6 and above, you can try:
>>> f'{6:08b}''00000110'
>>> f'{6:08b}'
Want to learn python in detail? Join python course fast!!
31k questions
32.8k answers
501 comments
693 users