[PLUG] Manipulating Bit Masks in Python

Brian Harring ferringb at gentoo.org
Wed Dec 28 07:50:50 UTC 2005


On Tue, Dec 27, 2005 at 04:00:17PM -0800, Rich Shepard wrote:
>   Has anyone here manipulated bit-masked data in Python? I'm having
> difficulties finding information on how to go about it.
> 
>   The Numerical Python (Nympy) doc has a chapter on masked arrays, but these
> are not the same thing; they're a mask that indicates which rows/columns 
> have valid data in an array.
> 
>   I'll be getting 2-bytes/row data from the optical mark reader and I need 
>   to
> test each bit in each byte to know what data are in each row. If you know of
> a reference that describes the preferred way to do this, please pass it on 
> to me.

I might be missing something obvious here, but the standard c bit op's 
are available in python; ^, &, |, >>, <<, etc.

Has to operate on ints in python, but any reason that wouldn't 
suffice?  A quick timeit test shows ops from above to be ~.27 uS for 
my semp. 2600, which is pretty quick python wise...

~harring



More information about the PLUG mailing list