在 Python 中进行位域操作的最佳方法是什么?操作、方法、Python

由网友(哥,依旧颓废)分享简介:我正在通过 UDP 读取一些 MPEG 传输流协议,其中包含一些时髦的位域(例如长度为 13).我正在使用struct"库进行广泛的拆包,但是有没有一种简单的方法可以说抓住接下来的 13 位"而不是手动调整位操作?我想要类似于 C 处理位字段的方式(无需恢复为 C).I'm reading some MPEG Tra...

我正在通过 UDP 读取一些 MPEG 传输流协议,其中包含一些时髦的位域(例如长度为 13).我正在使用struct"库进行广泛的拆包,但是有没有一种简单的方法可以说抓住接下来的 13 位"而不是手动调整位操作?我想要类似于 C 处理位字段的方式(无需恢复为 C).

I'm reading some MPEG Transport Stream protocol over UDP and it has some funky bitfields in it (length 13 for example). I'm using the "struct" library to do the broad unpacking, but is there a simple way to say "Grab the next 13 bits" rather than have to hand-tweak the bit manipulation? I'd like something like the way C does bit fields (without having to revert to C).

建议?

推荐答案

这是一个经常被问到的问题.上面有一个 ASPN Cookbook 条目,过去曾为我服务过.

It's an often-asked question. There's an ASPN Cookbook entry on it that has served me in the past.

还有一个一个人希望从执行此操作的模块中看到的广泛需求页面.

阅读全文

相关推荐

最新文章