Python bin() Builtin Function

Python bin() builtin function takes integer as argument and returns the binary representation of the given integer.

In this tutorial, we will learn how to find the binary representation of a number using bin() builtin function.

Syntax

The syntax to get the binary representation of an integer x is

</>
Copy
bin(x)

where

ParameterRequired/OptionalDescription
xRequiredAn integer value.

Example

In this example, we will take take an integer value in variable x and find its binary representation using bin() builtin function.

Python Program

</>
Copy
x = 87
result = bin(x)
print(f'bin({x}) returns {result}')

Output

bin(87) returns 0b1010111

Conclusion

In this Python Tutorial, we learned about bin() builtin function in Python, with the help of example programs.