Python Script – Convert Decimal to Hexadecimal
# Python script for decimal to Hexadecimal conversion
# (Example : Input = 65024 Output = FE00)
table = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
In1 = input("Input, Enter a decimal number = ")
In1_decimal = int(In1)
hexdec1 = ''
while (In1_decimal > 0):
remainder1 = In1_decimal % 16
hexdec1 = table[remainder1] + hexdec1
In1_decimal = In1_decimal // 16
print("Output, Hexadecimal number is = ", hexdec1)
Python Script – Convert Hexadecimal to Python
# Python script for Hexadecimal to Decimal conversion
# (Example : Input = AB5F , Output = 43871)
table1 = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 'A': 10, 'B': 11,
'C': 12, 'D': 13, 'E': 14, 'F': 15}
hexadecimal2 = input("Input, Enter the hexadecimal number = ").strip().upper()
decimal = 0
# computing max power value
power = len(hexadecimal2) - 1
for digit in hexadecimal2:
decimal += table1[digit] * 16 ** power
power -= 1
print("Output, decimal number is =", decimal)
Input and Output Deciman to Hexadecimal
Input, Enter a decimal number = 65024
Output, Hexadecimal number is = FE00
Input and Output Hexadecimal to Decimal
Input, Enter the hexadecimal number = AB5F
Output, decimal number is = 43871