Python bin() Function

Python Python Basic

bin() is a Python built-in function to return a binary string of an integer number. The return string value has prefix ‘0b’ or ‘-0b’.

Example 1 - bin() with zero number

x = bin(0)
print(x)
Output:

0b0

Example 2 - bin() with positive integer number

x = bin(5)
print(x)

x = bin(250)
print(x)
Output:

0b101
0b11111010

Example 3 - bin() with negative integer number

x = bin(-5)
print(x)

x = bin(-250)
print(x)
Output:

-0b101
-0b11111010