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 中进行位域操作的最佳方法是什么?


基础教程推荐
- 修改列表中的数据帧不起作用 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 包装空间模型 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01