CKTIS / Python
bin()
Formats an integer in base two with a binary prefix.
Version: Python 3.14; repository image, production runtime not attested
Syntax
bin(integer, /)Formats an integer in base two with a binary prefix.
Negative inputs carry a leading minus sign; this representation does not use a fixed-width two’s complement encoding.
Binary digits 1010 represent 8 + 2. The textual result uses the prefix 0b and a minus sign before that prefix for negative input. It has no fixed word width. Objects supplying __index__ qualify as integral inputs.
assert bin(10) == "0b1010" and bin(-10) == "-0b1010"
assert int(bin(-10), 2) == -10
Examples
print(bin(10))
print(bin(-10))
Result
0b1010 -0b1010
Binary digits 1010 represent 8 + 2. The textual result uses the prefix 0b and a minus sign before that prefix for negative input. It has no fixed word width. Objects supplying `__index__` qualify as integral inputs.