BitVector

castironpi at gmail.com castironpi at gmail.com
Mon Mar 10 07:39:03 CET 2008


> > I am trying to solve a genetic algorithm problem where I want to read
> > a bitvector of very large size (say 10000) and manipulate bits based
> > on certain algorithms.

Here's one on the Python website:
http://search.live.com/results.aspx?q=python+bitvector&src=IE-SearchBox
=> http://pypi.python.org/pypi/BitVector/1.3
=> http://cobweb.ecn.purdue.edu/~kak/dist/BitVector-1.3.html
code=> http://cobweb.ecn.purdue.edu/~kak/dist/BitVector_1.3_CodeOnly.py.html

"The bits of a bit array are stored in 16-bit unsigned ints."

However, Python has variable size longs.  Do you want something less
elaborate?

Here is what I think of when you say bitvector:

bA= bitvector()
bA[3]= 0
bA[7]= 1
bA[2].set()
bA[1]^= b[9]
bA[2:6].set()
rangeA= ba[2:7]
rangeA= "011101"
rangeA.clear()

bytearray is kind of close, but new in Py 3.0.  How close is it to the
perspective of the application you're writing?

Here's some of it straight off the console:

>>> b= bytearray(5)
>>> b
bytearray(b'\x00\x00\x00\x00\x00')
>>> b[1]= 1
>>> b
bytearray(b'\x00\x01\x00\x00\x00')
>>> list(b)
[0, 1, 0, 0, 0]




More information about the Python-list mailing list