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 data types of fixed bit size and utils for bit manipulations. It also contains types with support for 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
# [note] == is not overloaded, because it would make the values unhashable
#        because of support of partially valid values which can not be compared
assert a[0]._eq(1)
assert a[0]._dtype.bit_length() == 1
assert a[1]._eq(0)
assert a[8:]._eq(1)
assert a[8:]._dtype.bit_length() == 8

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

# bitwise operations
c = a >> 8
assert c._eq(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

Similar projects

  • hwtypes - Python implementations of fixed size hardware types

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.7.tar.gz (16.7 kB view details)

Uploaded Source

File details

Details for the file pyMathBitPrecise-0.7.tar.gz.

File metadata

  • Download URL: pyMathBitPrecise-0.7.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.3

File hashes

Hashes for pyMathBitPrecise-0.7.tar.gz
Algorithm Hash digest
SHA256 5f6ce99137ee44cfb1612d8b291f83c97046a9017d93e9a8e8bcdc46da29b7c7
MD5 705183d5602d5bb3c7e240ccbe1c8e3b
BLAKE2b-256 afc3de468c75146328924c50088517a288e63261193d48f1163caa3dab6cbad4

See more details on using hashes here.

Supported by

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