Python – Convert Hex to Decimal


Convert Hex to Decimal

To convert a given hexadecimal number to a decimal number in Python, call the builtin function int() and pass the hex number, and base=16 as arguments. int() converts the given value using the specified base, and returns the decimal number.


In this example, we write a function to read a decimal number from user, convert it to hex, and print the result to standard output.

Python Program

h = input('Enter hex : ')
d = int(h, base=16)
print('Decimal :', d)

Output #1

Enter hex : A2
Decimal : 162

Output #2

Enter hex : FFFA
Decimal : 65530


In this Python Examples tutorial, we learned how to convert hexadecimal number to decimal number using int() builtin function.

Related Tutorials

Code copied to clipboard successfully 👍