Skip to main content

number types of variable bit size and utils for bit manipulations

Project description

pyMathBitPrecise

Build Status Coverage Status PyPI version Documentation Status Python version

This library contains number types of variable bit size and utils for bit manipulations. Thre are also types which support tri state values etc. (Python equivalents of VHDL std_logic_vector, Verilog wire/reg.)

This may be usefull for tools which are simulating hardware or software which needs numbers of exact size.

Example

from pyMathBitPrecise.bits3t import Bits3t

#3t means that bits can have values 1,0,x
uint512_t = Bits3t(512, signed=False)

a = uint512_t.from_py(1)

# indexing on bits
assert a[0] == 1
assert a[0]._dtype.bit_length() == 1
assert a[1] == 0
assert a[8:] == 1
assert a[8:]._dtype.bit_length() == 8

# arithmetic
b = a + 1
assert b == 2
assert b._dtype == uint512_t

# bitwise operations
c = a >> 8
assert c == 0
assert c._dtype == uint512_t

# casting
d = int(a)
assert d == 1 and isinstance(d, int)

uint8_t = Bits3t(8, signed=False)
e = a.cast(uint8_t)
assert e._dtype == uint8_t

Project details


Download files

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

Source Distribution

pyMathBitPrecise-0.1.tar.gz (10.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page