hwtypes is a Python library providing implementations of fixed-size hardware types such as Bit, BitVector, UInt, and SInt. These types are designed to mimic hardware semantics, including explicit bit-widths and modular arithmetic, based on SMT-LIB2 specifications. The current version is 1.4.7, with an active but less frequent release cadence focused on stability and core functionality.
pip install hwtypesVerified import paths — ran on the pinned version, not inferred.
Demonstrates the basic usage of Bit, BitVector, UInt, and SInt types, including their initialization and simple arithmetic operations, highlighting the bit-width specification and distinct arithmetic semantics.
Use `SInt[N](value)` or `UInt[N](value)` for operations requiring specific signed/unsigned behavior. Be aware of `BitVector`'s modular arithmetic for raw bit manipulation.
Always specify the bit-width `[N]` when defining hardware types. For operations with mixed widths, use casting methods like `.as_type(NewType)` or `.resize(N)`.
Assign the result of any operation to a new variable (e.g., `c = a & b`). Do not expect in-place modification.
Specify the bit-width using bracket notation: `BitVector[8](value)` or `UInt[16](value)`.
Ensure all operands have the same bit-width, or explicitly cast one to match the other's width, e.g., `bv8 + bv16.as_type(BitVector[8])`.
Use the indexed type constructor with the desired bit-width, e.g., `BitVector[N](value)` instead of `BitVector(value)`.
No dependency data recorded yet.