BitArray is a lightweight class for bit-level data manipulation and management.
It is implemented in both C++ and Python, and can be used in areas such as networking, data compression, and binary analysis.
BitArray-main/
├── cpp/ # C++ implementation
│ ├── BitArray.hpp
│ ├── BitArray.cpp
│ ├── main.cpp
│ └── README.md
├── python/ # Python implementation
│ ├── BitArray.py
│ └── README.md
├── README.md # Project introduction
├── LICENSE
└── .gitignore
| Feature | Description |
|---|---|
| Bit Initialization | Create bit arrays from byte arrays or specified bit sizes |
| Bit Extraction | Extract sub-bit arrays based on offset and length |
| Bit Merging | Merge another bit array at a specified position |
| Bit Operations | Supports operators like +, <<, >> |
| Bit Reversal | Supports reverser() to reverse bit order |
| Visualization | Print bits in human-readable format using print, dump |
| Unit Testing | Includes test code for various operations |
- Source files:
cpp/ - Main class:
BitArray - High-performance implementation based on STL
- Includes unit test (
main.cpp) - Highlights:
- Uses
std::vector<uint8_t>for storage - Offers various bit manipulation methods like
get,merge,toArray,dump
- Uses
📄 More details: cpp/README.md
- Source files:
python/ - Main class:
BitArray - Implemented using Python lists and bit manipulation
- Highlights:
- Supports merging and extracting bit arrays
- Provides
to_array,to_int_array,reverser,__add__,__rshift__,__lshift__ - Includes unit test function
📄 More details: python/README.md
BitArray a({0b11000000}, 3);
a.print(); // Output: 110
BitArray b({0b01000000}, 2);
auto c = a + b;
c.print(); // Output: 11001bit_array = BitArray([0b11000000], 8)
bit_array.print() # Output: 1100 0000
sub_array = bit_array.get(2, 3)
sub_array.print() # Output: 000cd cpp
g++ main.cpp -std=c++17 -o bitarray
./bitarraycd python
python3 BitArray.py # Runs runTests() internallyEach implementation includes unit test code to verify functionality upon execution.
- MIT License
- https://github.com/JayTwoLab/BitArray