Python Program to Convert Decimal to Hexadecimal

« Previous Program Next Program »

Convert Decimal to Hexadecimal in Python

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

Python Programming Code to Convert Decimal to Hexadecimal

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

# Python Program - Convert Decimal to Hexadecimal

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

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

This is the output (initial output) shown after running the above program:

decimal to hexadecimal python

Now enter any number in decimal say 50 and press enter to find out the same number in hexadecimal format as shown here:

convert decimal to hexadecimal python

Here is the same program directly written and run on python shell:

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