0

Is there a way to reverse the hex() method of a float in Python? For example,

n = 1280.03125
n_hex = n.hex() 
print(n_hex)  # result--> 0x1.4002000000000p+10    

How can I convert 0x1.4002000000000p+10 back to 1280.03125? I know you can use int(num, base) to convert a number to integer but it doesn't support decimal.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65

1 Answers1

2

Try float.fromhex(str):

>>> float.fromhex("0x1.4002000000000p+10")
1280.03125
tekknolagi
  • 10,663
  • 24
  • 75
  • 119