在Python中进行位域操作的最佳方法是什么? [英] What is the best way to do Bit Field manipulation in Python?

查看:512
本文介绍了在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食谱条目.

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

并且有一个一个人希望从执行此操作的模块中看到的大量要求.

And there is an extensive page of requirements one person would like to see from a module doing this.

这篇关于在Python中进行位域操作的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆