Converting hex string representation to float in python

半城伤御伤魂 提交于 2020-07-18 09:35:19

问题


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?


回答1:


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

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




回答2:


Ah ha:

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

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



来源:https://stackoverflow.com/questions/34002545/converting-hex-string-representation-to-float-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!