10

I have data in IEEE 745 hexadecimal format: 0x1.5c28f5c28f5c3p-1

How would I convert this to a float in python? is this a standard module?

wjandrea
  • 28,235
  • 9
  • 60
  • 81
darktachyon
  • 258
  • 1
  • 2
  • 8

2 Answers2

18
>>> float.fromhex('0x1.5c28f5c28f5c3p-1')
0.68

It's in the standard library, float.fromhex.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
8

Ah ha:

It's in the standard library, "float.fromhex",

https://docs.python.org/2/library/stdtypes.html#float.fromhex

darktachyon
  • 258
  • 1
  • 2
  • 8