BitMap for python
This package provides a BitMap class which is an array of bits stored in compact format.
Installation
bitmap can be installed from pip:
$ sudo pip install bitmapFunctions
-
BitMap(maxnum): construct aBitMapobject withmaxnumbits -
set(pos): set the bit at positionposto 1 -
reset(pos): reset the bit at positionposto 0 -
flip(pos): flip the bit at positionpos -
count(): return the number of 1s -
size(): return the size of theBitMap -
test(pos): check if bit at positionposhas been set to 1 -
any(): check if any bit in theBitMaphas been set to 1 -
none(): check if none of the bits in theBitMaphas been set to 1 -
all(): check if all bits in theBitMaphas been set to 1 -
nonzero(): return indexes of all non-zero bits -
tostring(): convert aBitMapobject to0and1string -
fromstring(bitstring): create aBitMapobject from0and1string
Examples
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()