We have discussed in the previous tutorials, how to handle different types of number systems in python language. In this tutorials we are going to see how to convert any number into python binary number.

Number to Python Binary Number :

We can convert any number (whether it is octal, hexadecimal or decimal) in to a binary number in python.

To do this python gives us bin method. python bin() method takes the number as a parameter and convert it as corresponding binary number. Lets see how it works with all numbers.

Decimal to Python bin() :

I am going to convert a decimal number to binary number.

>>>x= 1234



Octal to Python bin() :

I am going to convert a octal number to binary number.




Hexadecimal to Python bin () :

I am going to convert a hexadecimal number to python binary number.




Note: we can even pass the binary number to bin() method, but it differ nothing.


References :

Python Built in Functions

Happy Learning 🙂