Skip to main content

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)

Documentation Status

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 - False
  • 1 - True
  • W - Weak Unknown: either True or False, propagates optimistically
  • X - 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bvwx-0.23.0.tar.gz (36.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bvwx-0.23.0-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file bvwx-0.23.0.tar.gz.

File metadata

  • Download URL: bvwx-0.23.0.tar.gz
  • Upload date:
  • Size: 36.3 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for bvwx-0.23.0.tar.gz
Algorithm Hash digest
SHA256 29ae4a94a248ce9f6939104b6cc65df10cd9aac8a22aa6325ee639b099a5ccb7
MD5 2ee20b5aba87eff066efb765185f8004
BLAKE2b-256 b374443d4caf5d55bcc20e97ea41a6b68375e6e70391aef2d675550110eb2d0b

See more details on using hashes here.

File details

Details for the file bvwx-0.23.0-py3-none-any.whl.

File metadata

  • Download URL: bvwx-0.23.0-py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for bvwx-0.23.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c616bf7bc7f3b2bdbbb3f7581a135aa81e52e35d445d5ddef6680025022f56be
MD5 e3315c8a006e73000a0b27343f0ec8dd
BLAKE2b-256 8beeeefbe7b5e7cf6970d7d4e3a60d908fd1bff86fd26aeb549d6622f54d81b7

See more details on using hashes here.

Release history Release notifications | RSS feed

0.24.0

2 files

This release

0.23.0 This release

2 files

0.22.2

2 files

0.22.1

2 files

0.22.0

2 files

0.21.0

2 files

0.20.0

2 files

0.19.1

2 files

0.19.0

2 files

0.18.0

2 files

0.17.0

2 files

0.16.0

2 files

0.15.0

2 files

0.14.0

2 files

0.13.4

2 files

0.13.3

2 files

0.13.2

2 files

0.13.1

2 files

0.13.0

2 files

0.12.2

2 files

0.12.1

2 files

0.12.0

2 files

0.11.1

2 files

0.11.0

2 files

0.10.0

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page