Python Program to Convert Decimal to Hexadecimal


In this post, we will see how to convert the decimal number into hexadecimal number using the built-in Python function.
The python hex() function converts an integer number to a lowercase hexadecimal string prefixed with “0x”.

  • 0x prefix :- represent hexadecimal
  • 0b prefix :- represent binary
  • 0o prefix :-represent octal

Python Program to Convert Decimal to Hexadecimal

# Python program to convert decimal number to hexadecimal number

# Getting the decimal number from user

decimal_number = int(input("Enter the decimal number for conversion in Hexadecimal: "))

# converting decimal  to hexadecimal  using built-in function hex()
hex_num = hex(decimal_number)

print("The equivalent hexadecimal number is: ", hex_num)

Output:-

Enter the decimal number for conversion in Hexadecimal: 525
('The equivalent hexadecimal number is: ', '0x20d')

 

 


 

Leave a Reply

Your email address will not be published. Required fields are marked *