使用Python3内置方法struct
hex转float
import struct
a=[0x45,0xaf,0xb9,0xdd]
s=struct.unpack(">f",bytes(a))[0] #5623.23291015625
b=`45afb9dd`
s=struct.unpack('>f',bytes.fromhex(b))[0] # 5623.23291015625
- 其中struct.unpack返回的是一个元组
float转hex
import struct
s=5623.23291015625
struct.pack('>f' ,float(s)).hex() #`45afb9dd`