I want to use a bit array in Python that I could use like the standard bitset from C++. Example:
#include<bitset>
int main() {
std::bitset<100> numBits;
}
However, I don't know if there is something similar in Python, preferably built-in.
Bitset represents a fixed-size sequence of N bits and stores values either 0 or 1. Zero means value is false or bit is unset and one means value is true or bit is set. Bitset class emulates space efficient array of boolean values, where each element occupies only one bit.
Bitset is a container in C++ Standard Template Library for dealing with data at the bit level. 1. A bitset stores bits (elements with only two possible values: 0 or 1). We can however get the part of a string by providing positions to bitset constructor (Positions are with respect to string position from left to right)
A Python interface to the fast bitsets in Sage. Bitsets are fast binary sets that store elements by toggling bits in an array of numbers. A bitset can store values between and capacity - 1 , inclusive (where capacity is finite, but arbitrary).
Second, bitset is not a Sequence; in fact, it is not an STL Container at all.
Normally, you just the builtin int
class (or long
in python2). Maybe wrap it in a class if you particularly care about hiding the shifts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With