[Tutor] working with bit arrays

GilJohnson x7-g5W_rt at earthlink.net
Thu Dec 3 22:13:48 CET 2009


Dave Angel <davea <at> ieee.org> writes:

> Once you have an *array* of integers, you have much more than 32 bits to 
> work with.  For example, with an array of size 10, you now have 320 bits 
> to work with.  He's just pointing out that it's a little bit awkward to 
> address a group of bits that are not all in the same int.  So bits 5-20 
> would be easy, while bits 29-40 would be much harder.
> 
> DaveA
> 
To all, especially DaveA,
Dave is right, I'm talking about a bit array made up of integers, so it can be
of arbitrary size.
To anyone who tried _using_ the bit array on the Python Wiki, I-have to
apologize - I screwed up the listing. In the definition of makeBitArray(), the
initialization of the integer array should read:

bitArray = array.array('I')          # 'I' = unsigned 32-bit integer
bitArray.extend((fill,) * intSize)

instead of the one-line:

bitArray = array.array('I', fill) * intsize

The new version works in Python 2.6 and 3.x, and the Wiki has been corrected.
Gil






More information about the Tutor mailing list