[SciPy-user] Manipulating Bit-Masked Data

Dave Kuhlman dkuhlman at cutter.rexx.com
Tue Dec 27 22:18:19 CST 2005

On Tue, Dec 27, 2005 at 04:55:47PM -0800, Rich Shepard wrote:
>    I need to read bit-masked bytes from an Optical Mark Recognition card
> reader. I'm quite new to Python and haven't found any documentation on how to
> manipulate bits. NumPy has masked arrays, but that's a different situation.
> My rummaging around the SciPy wiki and a search of the mail list archives
> turned up nothing.
>    I'd appreciate a pointer to documentation that will show me how to
> manipulate bit-masks in Python.

Define your hex masks with things like 0x1f.  See:

And, I believe, the bit-wise operators you want are "&", "^", and
"|" (and, xor, and or).  See:

Also, the built-in functions ord() and hex() may be useful.  See:

If you need lots of speed while doing this, you may want to look into
Pyrex.  But, that's an advanced topic.

Hope this helps.


Dave Kuhlman

More information about the SciPy-user mailing list