Python bin function

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.

Syntax of bin()

  • 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

print("binary value of",num,"is:",bin(num))


binary value of 5 is: 0b101


  • 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 2power  .

  • first place is 20 .
  • 2nd place is 21.
  • 3rd place is 22
  • and so on.





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

22+ 20 = 4+1=5


One thought on “Python bin function”

Comments are closed.