Python Program to Convert Binary to Hexadecimal

« Previous Program Next Program »

Convert Binary to Hexadecimal in Python

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

Python Programming Code to Convert Binary to Hexadecimal

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

# Python Program - Convert Binary to Hexadecimal

print("Enter 'x' for exit.");
binary = input("Enter a number in Binary Format: ");
if binary == 'x':
    temp = int(binary, 2);
    print(binary,"in Hexadecimal =",hex(temp));

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

binary to hexadecimal python

Above is the demo screenshot of initial sample output produced by above program, now enter any number in binary say 110 and press enter to see the same in hexadecimal form as shown here in below sample run:

convert binary to hexadecimal python

Below is the same program on python shell:

python convert binary to hexadecimal

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