Bits from Numbers.

Miki Tebeka miki.tebeka at zoran.com
Thu Jan 8 04:57:29 EST 2004


Hello Scott,

> I am whacking away at some code to view numbers as bit sequences.
> While this is not complete, I'd appreciate some feedback from anyone
> who is interested in looking at it:
>      http://members.dsl-only.net/~daniels/bits.html
Looks great. 

Several things:
1. I think a new object "bitarray" which will be a subclass of "list" will be 
   more "natural". Then you'll get:
   bitcount(n) -> n.count(1)
   bit(n, x) -> n[x]
   extract(x, lo, hi) -> n[lo:high]
   ...
2. There is no function to set a range of bits n = setbits(n, start, end, value)
3. I'd prototype it first in Python and after the interface has matured move it 
   to C. This way you'll be able to make changes faster. (This is the way the 
   Python library works - see sets, itertools, heapq ...)

HTH.
Miki.



More information about the Python-list mailing list