On Wed, Dec 2, 2009 at 1:08 PM, Robert Berman <berma...@cfl.rr.com> wrote:
> Hi,
>
> I am trying to represent a number as a list of bits: for example the bit
> representation of the integer 8. I did find a number of articles pertaining
> to a module called bitarray but I was unable to download/install that
> package. I am using Linux on Ubuntu 9.10; Python 2.6.2.
>
> I am almost certain there is a relatively easy way to convert an integer
> that can be represented by 32 bits into an array of bits that I can iterate
> over looking for switched on bits or switched off bits.

If all you want to do is test bits, you can do that directly using
bit-wise logical operators & and |. There is no need to convert to a
different representation. For example

In [1]: 0xff & 4
Out[1]: 4

In [2]: 0xf0 & 4
Out[2]: 0

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to