Bit Vectors With Xes
BVWX (pronounced bih-vuh-wax, like "bivouacs") is a Python library that implements a family of hardware-oriented, bit vector data types and operators.
Read the docs! (WIP)
Features
Data Types
The fundamental BVWX data type is an ordered collection of "bits".
Unlike standard Boolean algebra where bit values are restricted to {0, 1},
BVWX extends this to include hardware-oriented values W (don't care),
and X (exception).
This lifted, four-state logic consists of:
0- False1- TrueW- Weak Unknown: either True or False, propagates optimisticallyX- Strong Unknown: neither True nor False, propagates pessimistically
W may also be denoted by - in string literals.
The - character is a convention from the Espresso PLA file format.
Wherever it hampers readability, we will instead use W.
Collections of bits can be organized into arbitrary shapes using the
multi-dimensional Array class factory.
Enum, Struct, and Union class factories can be extended to create
user-defined abstract date types.
Operators
BVWX implements several operators necessary for implementing Boolean algorithms. This includes standard NOT, OR, AND, XOR, ITE (if-then-else), and MUX functions, but also efficient implementations of arithmetic, comparison, shift, rotate, extend, concatenate, pack, encode/decode, and bit count.
See Operators section of the reference documentation for a full list.
Example
>>> from bvwx import *
>>> x0 = bits(["4b----", "4b1111", "4b0000", "4bXXXX"])
>>> x1 = bits(["4b-10X", "4b-10X", "4b-10X", "4b-10X"])
>>> # Bitwise Operators
>>> ~x0
bits(["4b----", "4b0000", "4b1111", "4bXXXX"])
>>> ~x1
bits(["4b-01X", "4b-01X", "4b-01X", "4b-01X"])
>>> x0 | x1
bits(["4b-1-X", "4b111X", "4b-10X", "4bXXXX"])
>>> x0 & x1
bits(["4b--0X", "4b-10X", "4b000X", "4bXXXX"])
>>> x0 ^ x1
bits(["4b---X", "4b-01X", "4b-10X", "4bXXXX"])
>>> # Enums
>>> class Color(Enum):
... RED = "2b00"
... GREEN = "2b01"
... BLUE = "2b10"
...
>>> Color.GREEN & Color.BLUE
Color.RED
>>> # Structs
>>> class Pixel(Struct):
... r: Array[8]
... g: Array[8]
... b: Array[8]
...
>>> maize = Pixel(r="8hFF", g="8hCB", b="8h05")
>>> blue = Pixel(r="8h00", g="8h27", b="8h4C")
>>> maize & blue
Pixel(
r=bits("8b0000_0000"),
g=bits("8b0000_0011"),
b=bits("8b0000_0100"),
)
>>> # And much more ...
Installing
BVWX is available on PyPI:
$ pip install bvwx
It requires Python 3.12+
Developing
BVWX's repository is on GitHub:
$ git clone https://github.com/cjdrake/bvwx.git
It is 100% Python, and has no runtime dependencies.
Development dependencies are listed in requirements-dev.txt.
Metadata
Release files for bvwx 0.24.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bvwx-0.24.0.tar.gz | 36.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bvwx-0.24.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 65.8 kB
Release files / bvwx-0.24.0.tar.gz
| Download URL | bvwx-0.24.0.tar.gz |
|---|---|
| Size | 36.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ad1875cd3b3b1a8fd0f2a8ebb069f644051427251577c9486296fbee6406abd2
|
|
BLAKE2b-256 checksum How to use checksums |
de57f0891ac25d87b27beab010386d90ef3007efa9ebd479cc07dc68286725ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / bvwx-0.24.0-py3-none-any.whl
| Download URL | bvwx-0.24.0-py3-none-any.whl |
|---|---|
| Size | 29.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
314856b97eb7197b6e1f4e6f058fcc587a74c087350eea37624c2249888d8fe4
|
|
BLAKE2b-256 checksum How to use checksums |
023f3156035c827bad7e78af881df0fa82526ebd05fae95ce0dccc842d8c47cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|