Solution
input_hex_string = input("Enter a hexadecimal number: ").strip()
try:
decimal_value = int(input_hex_string, 16)
print(f"Decimal: {decimal_value}")
print(f"Hexadecimal: {hex(decimal_value)[2:].upper()}")
except ValueError:
print("Error! Invalid hexadecimal input.")
Output:
Enter a hexadecimal number: 2E
Decimal: 46
Hexadecimal: 2E
Enter a hexadecimal number: FFFFFF
Decimal: 16777215
Hexadecimal: FFFFFF
Enter a hexadecimal number: CAFEBABE
Decimal: 3405691582
Hexadecimal: CAFEBABE

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!