Skip to main content

A pure-Python memory-efficient packed representation for bit arrays

Project description

This class presents a pure-Python memory efficient packed representation for bit arrays.

Version 1.5 should prove to be much more efficient for long bit vectors. Efficiency in BitVector construction when only its size is specified was achieved by eliminating calls to _setbit(). The application of logical operators to two BitVectors of equal length was also made efficient by eliminating calls to the padding function. Another feature of this version is the count_bits() method that returns the total number of bits set in a BitVector instance. Yet another feature of this version is the setValue() method that alters the bit pattern associated with a previously constructed BitVector.

In version 1.4.1, the reset() method now returns ‘self’ to allow for cascaded inovocation with the slicing operator. This version also removes the discrepancy between the value of the __copyright__ variable in the module and the value of license variable in

The class supports the following operators/methods:










__eq__, __ne__, __lt__, __le__, __gt__, __ge__

‘|’ for bitwise or

‘&’ for bitwise and

‘^’ for bitwise xor

‘~’ for bitwise inversion

‘<<’ for circular shift to the left

‘>>’ for circular shift to the right

‘+’ for concatenation

intValue(), __int__ for returning the integer value










slice assignment




Project details

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page