What is the best way to do Bit Field manipulation in Python?(在 Python 中进行位域操作的最佳方法是什么?)
问题描述
我正在通过 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 中进行位域操作的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Python 中进行位域操作的最佳方法是什么?


- 我如何透明地重定向一个Python导入? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01