This package provides a BitMap
class which is an array of bits stored in compact format.
bitmap
can be installed from pip
:
$ sudo pip install bitmap
BitMap(maxnum)
: construct aBitMap
object withmaxnum
bitsset(pos)
: set the bit at positionpos
to 1reset(pos)
: reset the bit at positionpos
to 0flip(pos)
: flip the bit at positionpos
count()
: return the number of 1ssize()
: return the size of theBitMap
test(pos)
: check if bit at positionpos
has been set to 1any()
: check if any bit in theBitMap
has been set to 1none()
: check if none of the bits in theBitMap
has been set to 1all()
: check if all bits in theBitMap
has been set to 1nonzero()
: return indexes of all non-zero bitstostring()
: convert aBitMap
object to0
and1
stringfromstring(bitstring)
: create aBitMap
object from0
and1
string
from bitmap import BitMap
bm = BitMap(32)
print bm.tostring()
bm.set(1)
print bm.tostring()
bm = BitMap.fromstring("00011101")
print bm.tostring()
bm.flip(1)
print bm.tostring()