An updated version of the bitmap library from https://github.com/wanji/bitmap
Project description
BitMap for python
An updated version of the bitmap library from https://github.com/wanji/bitmap since the original project is no longer maintained.
This package provides a BitMap
class which is an array of bits stored in compact format.
Installation
bitmap
can be installed from pip
:
pip3 install bitmap2
Functions
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 list of indexes of all non-zero bitsnonzeros()
: return generator of indexes of all non-zero bitszero()
: return list of indexes of all zero bitszeros()
: return generator of indexes of all zero bitstostring()
: convert aBitMap
object to0
and1
stringtofile(path)
: save aBitMap
object to a file onpath
fromstring(bitstring)
: create aBitMap
object from0
and1
stringfromhexstring(hexstring)
: construct aBitMap
object from hex stringfromfile(path, maxnum)
: construct aBitmap
object from a file atpath
of sizemaxnum
bits
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()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bitmap2-0.2.2.tar.gz
(8.4 kB
view hashes)