简体   繁体   English

Python 的 `struct` 字节大小计算

[英]Python's `struct` byte size calcualtion

Unfortunately I don't understand the byte size calculation of the struct python module.不幸的是,我不明白struct python 模块的字节大小计算。 I usethis documentation when encoding my values.我在编码我的值时使用此文档

import struct

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

but

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

using the encoding together requires 16 bytes instead of 10一起使用编码需要 16 个字节而不是 10 个

What could be/is the reason for this?这可能是/是什么原因? Thanks!谢谢!

Maybe this can help;也许这会有所帮助; Python struct giving incorrect length Python结构给出不正确的长度

struct.calcsize('=Hd')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM