Answer the question
In order to leave comments, you need to log in
How to convert from decimal to binary with a certain number of characters?
I know that there is a bin() function, is it possible to somehow specify the number of characters, let's say bin(3) will make 11, but I need 0011, can there be any analogue?
Answer the question
In order to leave comments, you need to log in
zfill will save a young programmer
>>> bin(777)[2:].zfill(22)
'0000000000001100001001'
>>> format(777, '022b')
'0000000000001100001001'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question