bitmask/README.md

52 lines
880 B
Markdown
Raw Permalink Normal View History

2022-07-31 19:35:09 -04:00
# Bitmask
2022-08-08 18:32:30 -04:00
Implementation of a Bitmask class in Python, allowing easy manipulation of IntFlag values.
2022-07-31 19:35:09 -04:00
## Features
2022-08-08 18:32:30 -04:00
* create bitmasks from any IntFlag type
2022-07-31 19:35:09 -04:00
* simple "flag in Bitmask" syntax
* bitwise operations, e.g. AND (&), OR (|), XOR (^)
* assignment with operators (+=, -=, &=, etc.)
* convenience functions like Bitmask.add(), or Bitmask.discard()
For development and tinkering:
* included unit tests
* ample documentation and examples in code
## Example usage
```python
from bitmask import Bitmask
from enum import IntFlag
class Desc(IntFlag):
SMALL = 1
ROUND = 1 << 1
FUNKY = 1 << 2
LARGE = 1 << 3
marble = Bitmask(Desc.SMALL, Desc.ROUND, Desc.FUNKY)
2022-07-31 19:35:09 -04:00
Desc.SMALL in marble
>>> True
Desc.LARGE in marble
>>> False
Bitmask(Desc.SMALL, Desc.ROUND) in marble
2022-07-31 19:35:09 -04:00
>>> True
```
## Installation
```
$ pip install git+https://github.com/dogeystamp/bitmask@main
```