【发布时间】:2016-12-21 06:08:13
【问题描述】:
//c struct code with filed width:
struct{
unsigned int x:1;
unsigned int y:25;
unsigned int z:6;
};
现在我想用python重写,打包发送到网络,
python中的包结构,可以打包/解包数据类型。
如:
struct.pack('!I10s',1,'hello')
但我不知道如何处理具有字段宽度的结构作为 c 结构示例。有谁知道吗?
【问题讨论】:
-
任何帮助stackoverflow.com/questions/7198388/… ??可能是骗子。
-
3q。我已经见过了。现在找到一个可能更好的链接,varx.org/wordpress/2016/02/03/bit-fields-in-python
-
只需将整个内容读取为无符号,然后进行屏蔽和移位。就像链接的文章一样。不过,位域的可移植性值得怀疑。