Friday , July 21 2017
Home / Python / Convert any Number to Python Binary Number

Convert any Number to Python Binary Number

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

>>>bin(x)

>>>'0b10011010010'

Octal to Python bin() :

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

>>>x=0o127

>>>bin(x)

>>>'0b1010111'

Hexadecimal to Python bin () :

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

>>>x=0x235f

>>>bin(x)

>>>'0b10001101011111'

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

 

References :

Python Built in Functions

Happy Learning 🙂

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Recommended

Python Number Systems Example

According to the mathematics we have 4 types of number systems which are representing the …

Leave a Reply

Your email address will not be published. Required fields are marked *