Convert Int to Binary in Python
Using the format method in Python, we can convert int to binary.
Conversion
Int -> N-bit
Specify 'b' in the format
method in Python.
Int -> 8-bit
We can specify 8-bit
by prepending {0:08b}
before the format
method.
Alternatively, zfill
method can be used for this purpose.
Int -> 16-bit
This is also the same as above, we can specify 16-bit
by prepending {0:016b}
, or zfill
method can be used.