Efficient Bit addressing in Python.

Hendrik van Rooyen mail at microcorp.co.za
Sun Oct 12 16:19:25 EDT 2008


Ross Ridge <rrid...lub.uwaterloo.ca>  wrote:

>Unfortunately from your other posts you do seem to be working on
>a single byte a time, so my technique probably won't be efficient.

Its a bit more - the hardware allows for 64 lines in and 64 lines out.

>You probably want just want to be using constants and bit masking.
>Something like:

8< -------------  standard and and or examples ----------------

This is approximately how I was doing it before I started the thread,
but I was unsatisfied, and started looking for a way to directly
address the bits, more as a further exploration of Python.

>Bit twiddling like this is pretty basic.

Yes it is, and in what we do it is also pervasive,
and I miss my 8051/8031 assembler instructions
where I can do an atomic "jump if bit set then clear' on
a named bit in the bit addressable space, as well as
a direct set or clear of a named bit, without resorting
to anding and oring of bytes.

Now I know that I can never do the jump in python, but
I had hoped that I could get close to the direct set
and clear, and the thread has been useful in that it
has rubbed my nose into a lot of corners where I would
otherwise never have gone. (like the gmpy stuff, for
instance, and mucking around with bitfield-like classes,
and the binascii stuff.)

And I now _almost_ have my direct bit addressability...

However - Python has failed to show me "the one and
only one obvious way".

*grins and ducks*

Thanks to all who responded.

- Hendrik







More information about the Python-list mailing list