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
  • 14,486
  • 4
  • 43
  • 54
Janey Jane
  • 63
  • 5

1 Answers1

2

Try float.fromhex(str):

>>> float.fromhex("0x1.4002000000000p+10")
1280.03125
tekknolagi
  • 10,089
  • 22
  • 71
  • 114