python中4位16进制数与float浮点数互相转换

论坛 期权论坛 脚本     
匿名技术用户   2020-12-22 19:32   2156   0
import struct
s = 'F4CEF042'
print(s)
#<是小端,>是大端,f代表浮点数
print(struct.unpack('<f', bytes.fromhex(s))[0])#小端
#输出:120.40420532226562
s = float('6.55563714424545E-10')
print(struct.pack('<f', s).hex())#小端
#输出:32333430
print(struct.pack('>f', s).hex())#大端
#输出:30343332
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP