我正在通过 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.
还有一个一个人希望从执行此操作的模块中看到的广泛需求页面.一个>
这篇关于在 Python 中进行位域操作的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!