[SciPy-user] Manipulating Bit-Masked Data

Rich Shepard rshepard at appl-ecosys.com
Wed Dec 28 18:01:54 CST 2005

On Tue, 27 Dec 2005, Travis Oliphant wrote:

> There are not intrinsic bit-fields in scipy, but you can easily access bits 
> of interest using an integer type, bit-masks, and the bit-operators.

> Perhaps you could show an example of what you would like to do.  I'd love
> to give a more specific response.


   Thanks (to you and the others who responded). I think the situation is
simpler than I realized, now that I've found and read the technical manual.

   The point of the exercise is to read OMR (Optical Mark Recognition) cards
and store the data in a SQLite database for analyses.

   The card has 12 rows (when held with the short ends on either side and the
long sides on top and bottom). Rows are numbered from 0-12, and data are
returned at two bytes. The right half of the card (rows 12, 11, 0, 1, 2, and
3 from LSB to MSB) is the first byte and the left half (rows 4, 5, 6, 7, 8,
and 9) are the second byte. In both bytes, the 6th bit is forced true so the
value of each byte is 32 when that "column" (or row if the card's held
upright) is blank. The maximum value would be 127 if all 12 boxes are filled.

   So, for my needs, the byte values will tell me which boxes were filled, and
I don't need to twiddle bits to get the required data.

   I still need to check with the vendor, but I believe that the number of
two-bytes-plus-CR represent all possible "rows" on the card ("columns" in the
vendor's orientation). So, by using the strobe marks to count, I can tell
which bubbles were filled and associate them with the data being scored.

   FWIW, I'm developing the form in LaTeX which is an interesting exercise in
itself. :-)


Richard B. Shepard, Ph.D.               |   Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM)   |  Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com>     Voice: 503-667-4517         Fax: 503-667-8863

More information about the SciPy-user mailing list