Skip to main content

uint CI Coverage Status

Fixed-width integer and calculation for Python

$ pip install uint

Fixed-width integers for Python

uint provides two classes: Uint and Int. They are calculated like int but is fixed-width so they behave like ones that you're familiar with ... like in C language.

In [1]: from uint import Uint, Int

In [2]: u, i = Uint(0xff, 8), Int(0xff, 8)

In [3]: u
Out[3]: <uint8, value=255>

In [4]: i
Out[4]: <int8, value=-1>

In [5]: u << 2 >> 1
Out[5]: <uint8, value=126>

In [6]: i << 2 >> 1
Out[6]: <int8, value=-2>

Of course they overflows when you do like:

In [1]: from uint import Uint, Int

In [2]: u, i = Uint(0xff, 8), Int(0x7f, 8)

In [3]: u, i
Out[3]: (<uint8, value=255>, <int8, value=127>)

In [4]: u+1, i+1
Out[4]: (<uint8, value=0>, <int8, value=-128>)

Register with multiple fields inside

The original purpose of this package is to reduce labor of calculating "register values" in several MCUs and SoCs. See examples directory for detailed usage.

In [1]: from uint import Register

In [2]: reg = Register('reg')

In [3]: reg[15:8] = 'f1'

In [4]: reg[7:0] = 'f2'

In [5]: reg['f1'] = 0x5A

In [6]: reg['f2'] = 0x0F

In [7]: hex(reg.encode())
Out[7]: '0x5a0f'

In [8]: reg.decode(0x1234)

In [9]: reg['f1'].value.wire.hex
Out[9]: "8'h12"

In [10]: reg['f2'].value.wire.hex
Out[10]: "8'h34"

Metadata

Release files for uint 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uint 0.2.1
File Size Uploaded Provenance
uint-0.2.1.tar.gz 7.1 kB Without provenance Details

Release files / uint-0.2.1.tar.gz

Download URL uint-0.2.1.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f114406f330c9d2caa1fc974280d3d19bab175191712fdb0475ba25941b685fd
BLAKE2b-256 checksum
How to use checksums
b95e423241e382403a3a52dd32a51298ca32bb63d0d404cf8e04e0b449a5191d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.2

Security for uint 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page