codescracker


python

Python Program to Convert Decimal to Binary



« Previous Program Next Program »


Convert Decimal to Binary in Python

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

Python Programming Code to Convert Decimal to Binary

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

# Python Program - Convert Decimal to Binary

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

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

decimal to binary python

Now enter any number in decimal number system say 50 and then press enter to check what will be the value of given number say 50 in binary format:

convert decimal to binary python

Below is the same program on python shell:

python convert decimal to binary

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 »








Tools
Calculator

Quick Links
Signup - Login - Give Online Test