gpt4 book ai didi

Python struct.calcsize 不适用于 QWord

转载 作者:太空宇宙 更新时间:2023-11-03 18:21:56 25 4
gpt4 key购买 nike

我不知道为什么这不起作用。我想使用 struct modul 读取 1 个整数(双字)和 4 个四字。这代表 4 + 4 * 8 = 36 字节,但 python 给了我这个:

>>> import struct
>>> struct.calcsize("I4Q")
40

有人知道为什么吗?非常感谢...

最佳答案

根据the documentation: Byte Order, Size, and Alignment :

By default, C types are represented in the machine’s native format and byte order, and properly aligned by skipping pad bytes if necessary (according to the rules used by the C compiler).

>>> struct.calcsize("I4Q")
40
>>> struct.calcsize("@I4Q")
40

如果您指定> , = , < , ! ,不使用 native 对齐:

>>> struct.calcsize(">I4Q")
36
>>> struct.calcsize("=I4Q")
36
>>> struct.calcsize("<I4Q")
36
>>> struct.calcsize("!I4Q")
36

关于Python struct.calcsize 不适用于 QWord,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23954478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com