codescracker


python

Python Program to Convert Hexadecimal to Binary



« Previous Program Next Program »


Convert Hexadecimal to Binary in Python

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

Python Programming Code to Convert Hexadecimal to Binary

Following python program ask from user to enter any number in hexadecimal format to convert it into binary format:

# Python Program - Convert Hexadecimal to Binary

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

Here is the sample run of the above Python program to illustrate how to convert hexadecimal to binary number:

hexadecimal to binary python

Now enter any number in hexadecimal and then press enter key to convert the same number in binary form, that is in 0 and 1 form as shown here:

convert hexadecimal to binary python

Here is the same program with run on python shell:

python convert hexadecimal to binary

Program Video with Compile and Run

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