Bit arrays.

Emile van Sebille emile at fenx.com
Thu Feb 10 22:39:29 EST 2000


I often set 'bit' style flags in integers, but leave them as
integers.  e.g., add 2^5+2^3+2^2 to an int to turn on bits
5,3,2 (or 4,2,1)

What will you be doing?

--


Emile van Sebille
emile at fenx.com
-------------------


----- Original Message -----
From: <rdudfield at my-deja.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Thursday, February 10, 2000 7:23 PM
Subject: Bit arrays.


> Hello,
>
> Just wondering if there is an efficient way in python to represent
> arrays or lists of bits?
>
>
>
>
>
> The way that I am thinking of doing it is to make a class in python
and
> do the following:
>
>
> Have set and get methods for arbitary places in the array.
>
> It would store the data in an array of ints ( not sure what size
yet ).
> The best size would depend on how you change/read the array.
>
> The set method would be implemented in the following way:
>
> *Find which element in the array of ints that the bit is in.
> *Convert that int into a tupple/list/array of 1s and 0s.
> *Find which place in the new list of 1s, and 0s the bit which needs
> changing.
> *Change that bit.
> *Convert the list back into a number.
>
>
> Get would be similar.
>
>
>
> I know this would be quite slow if you are doing lots of changes all
> over the array, but I am changing large ranges of bits at a time so it
> should be possible to cut out lots of conversions.
>
> Anyone think of better ways to do this?  It would probably be worth
> doing this as a module in c/c++ no?
>
>
> Thanks in advance for any help.
>
> Rene.
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
> --
> http://www.python.org/mailman/listinfo/python-list
>
>






More information about the Python-list mailing list