Python `bin()`

function is binary function and one of **Python built-in function**. bin() function is used to get the binary value of integer number. binary value is the value in the form of 0 and 1.

Page Contents

## Syntax of bin()

bin(number)

- bin is function name
- number is any integer value whose binary value need to be calculated.

## How bin() function works

Let’s see how bin() function works by taking example.

#Python bin() function num=5 print("binary value of",num,"is:",bin(num))

**Output**

binary value of 5 is: 0b101

**Explanation**

- In above example, we have to calculate the binary value of number 5.
- so, when we apply bin function over number 5, it gives output
**0b101,**here**0b**is binary indication and**101**is binary value.

**How to calculate binary value of number**

If you don’t know how to get binary value of any integer without any function, here we will describe.

for calculating binary value, binary value is calculated in 2^{power }.

- first place is 2
^{}. - 2nd place is 2
^{1}. - 3rd place is 2
^{2} - and so on.

hence in our example, binary value of 5 is calculated as

`2`

^{2}`+ 2`

^{}` = 4+1=5`

[…] bin() […]