Skip to main content

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 a BitMap object with maxnum bits
  • set(pos): set the bit at position pos to 1
  • reset(pos): reset the bit at position pos to 0
  • flip(pos): flip the bit at position pos
  • count(): return the number of 1s
  • size(): return the size of the BitMap
  • test(pos): check if bit at position pos has been set to 1
  • any(): check if any bit in the BitMap has been set to 1
  • none(): check if none of the bits in the BitMap has been set to 1
  • all(): check if all bits in the BitMap has been set to 1
  • nonzero(): return list of indexes of all non-zero bits
  • nonzeros(): return generator of indexes of all non-zero bits
  • zero(): return list of indexes of all zero bits
  • zeros(): return generator of indexes of all zero bits
  • tostring(): convert a BitMap object to 0 and 1 string
  • tofile(path): save a BitMap object to a file on path
  • fromstring(bitstring): create a BitMap object from 0 and 1 string
  • fromhexstring(hexstring): construct a BitMap object from hex string
  • fromfile(path, maxnum): construct a Bitmap object from a file at path of size maxnum 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


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.1.0.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file bitmap2-0.1.0.tar.gz.

File metadata

  • Download URL: bitmap2-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for bitmap2-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ea1b7a97ae4d6f2879ee87c741b7bd9c6e432bfa84c3670db832a811ca8697aa
MD5 0d175b2f0c2969fa703160fd64d7b543
BLAKE2b-256 bee429a3e1482e599a3c9acd3d23a10d70f21f9b0b8a8f4c2e164141ced67d5f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page