Python的`struct`字节大小计算

问题描述 投票:2回答:1

[不幸的是,我不理解struct python模块的字节大小计算。对值进行编码时,我使用this documentation

import struct

struct.calcsize('H') # == 2
struct.calcsize('d') # == 8

但是

struct.calcsize('Hd') # == 16 != 8+2

一起使用编码需要16个字节而不是10个字节

这可能是/是什么原因?谢谢!

python struct byte decoding
1个回答
1
投票

也许这会有所帮助; Python struct giving incorrect length

struct.calcsize('=Hd')
© www.soinside.com 2019 - 2024. All rights reserved.