Python Program to Convert Binary to Decimal

« Previous Program Next Program »

Convert Binary to Decimal in Python

To convert binary to decimal number in python, you have to ask from user to enter a number in binary number system to convert that number into decimal number system as shown in the program given here.

Python Programming Code to Convert Binary to Decimal

Following python program ask from user to enter binary number to convert it into decimal number:

# Python Program - Convert Binary to Decimal

print("Enter 'x' for exit.");
binary = input("Enter number in Binary Format: ");
if binary == 'x':
    decimal = int(binary, 2);
    print(binary,"in Decimal =",decimal);

Here is the sample run of the above Python program shows how to convert binary number to decimal number:

Below is the first or initial output that will be produced after executing/running the above program as shown here:

binary to decimal python

Now enter any number in binary format, that is in 0 and 1 form, say 10110 and press enter to find out the same number but in decimal form:

convert binary to decimal python

Or enter 0b10110 which will be same as 10110 and press enter to confirm the same value as in above output:

binary to decimal conversion python

Below is the same program on python shell:

python convert binary to decimal

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test