Python Program to Convert Hexadecimal to Decimal

« Previous Program Next Program »

Convert Hexadecimal to Decimal in Python

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

Python Programming Code to Convert Hexadecimal to Decimal

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

# Python Program - Convert Hexadecimal to Decimal

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

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

hexadecimal to decimal python

As you can see that above one is the screenshot of the initial output after running the above program, now enter any number in your mind in hexadecimal format and then press enter key to convert the same number in decimal form as shown here in given screenshot:

convert hexadecimal to decimal python

Below is the same program with run on python shell:

python convert hexadecimal 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