uintlib


Nameuintlib JSON
Version 2.0.0 PyPI version JSON
download
home_pageNone
SummaryA Python package to easily use uints/ints in Python.
upload_time2025-07-15 14:53:20
maintainerNone
docs_urlNone
authorrraptor06
requires_python>=3.6
licenseMIT
keywords python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # uintlib

A simple, lightweight Python library providing fixed-size unsigned and signed integer types  
(`UInt8`, `Int8`, `UInt16`, `Int16`, `UInt32`, `Int32`, `UInt64`, `Int64`) with correct wrapping behavior  
and easy arithmetic operations. Perfect for network programming, binary protocols, emulation, and low-level data manipulation.

---

## Why?

Python's built-in integers are unbounded and do not overflow, which is convenient but not suitable for all use cases, especially when working with:

- Binary protocols requiring precise bit widths  
- Network packet parsing and construction  
- Emulators or hardware interfacing code  
- Embedded systems data serialization/deserialization  
- Situations where overflow behavior must match C, Rust, Go, or other languages

This library provides integer classes that behave like fixed-size integers in low-level languages, including overflow wrapping and bit masking.

---

## Features

- Fixed bit widths: 8, 16, 32, and 64 bits  
- Both unsigned (`UInt*`) and signed (`Int*`) types  
- Proper overflow wrapping on arithmetic operations (`+`, `-`)  
- Supports comparison operators (`==`, `!=`, `<`, `>`, etc.)  
- Intuitive constructor with automatic bit masking  
- Supports integer conversion via `int()`  
- Easy to extend or customize  
- Lightweight, no external dependencies  

---

## Installation

You can install from PyPI (once published) using:

    pip install uintlib

---

## Usage

```python
from uintlib.uint import UInt8, Int16, UInt32, Int64

a = UInt8(250)
b = UInt8(10)

print(a + b)          # UInt8(4) — wraps around at 255 (250 + 10 = 260 → 4)
print(int(a + b))     # 4 as Python int

x = Int16(-20000)
y = Int16(10000)

print(x + y)          # Int16(-10000) — correct 16-bit signed overflow
print(int(x + y))     # -10000

# Comparisons work as expected
print(a == UInt8(4))  # True
print(x < y)          # True
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "uintlib",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "python",
    "author": "rraptor06",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/ea/f2/6016508ba191acd7c8de30bb25eee8ddb023dcf97ff3a275ef18d9c58dbb/uintlib-2.0.0.tar.gz",
    "platform": null,
    "description": "# uintlib\r\n\r\nA simple, lightweight Python library providing fixed-size unsigned and signed integer types  \r\n(`UInt8`, `Int8`, `UInt16`, `Int16`, `UInt32`, `Int32`, `UInt64`, `Int64`) with correct wrapping behavior  \r\nand easy arithmetic operations. Perfect for network programming, binary protocols, emulation, and low-level data manipulation.\r\n\r\n---\r\n\r\n## Why?\r\n\r\nPython's built-in integers are unbounded and do not overflow, which is convenient but not suitable for all use cases, especially when working with:\r\n\r\n- Binary protocols requiring precise bit widths  \r\n- Network packet parsing and construction  \r\n- Emulators or hardware interfacing code  \r\n- Embedded systems data serialization/deserialization  \r\n- Situations where overflow behavior must match C, Rust, Go, or other languages\r\n\r\nThis library provides integer classes that behave like fixed-size integers in low-level languages, including overflow wrapping and bit masking.\r\n\r\n---\r\n\r\n## Features\r\n\r\n- Fixed bit widths: 8, 16, 32, and 64 bits  \r\n- Both unsigned (`UInt*`) and signed (`Int*`) types  \r\n- Proper overflow wrapping on arithmetic operations (`+`, `-`)  \r\n- Supports comparison operators (`==`, `!=`, `<`, `>`, etc.)  \r\n- Intuitive constructor with automatic bit masking  \r\n- Supports integer conversion via `int()`  \r\n- Easy to extend or customize  \r\n- Lightweight, no external dependencies  \r\n\r\n---\r\n\r\n## Installation\r\n\r\nYou can install from PyPI (once published) using:\r\n\r\n    pip install uintlib\r\n\r\n---\r\n\r\n## Usage\r\n\r\n```python\r\nfrom uintlib.uint import UInt8, Int16, UInt32, Int64\r\n\r\na = UInt8(250)\r\nb = UInt8(10)\r\n\r\nprint(a + b)          # UInt8(4) \u2014 wraps around at 255 (250 + 10 = 260 \u2192 4)\r\nprint(int(a + b))     # 4 as Python int\r\n\r\nx = Int16(-20000)\r\ny = Int16(10000)\r\n\r\nprint(x + y)          # Int16(-10000) \u2014 correct 16-bit signed overflow\r\nprint(int(x + y))     # -10000\r\n\r\n# Comparisons work as expected\r\nprint(a == UInt8(4))  # True\r\nprint(x < y)          # True\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python package to easily use uints/ints in Python. ",
    "version": "2.0.0",
    "project_urls": null,
    "split_keywords": [
        "python"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "359b6b2d7a033c1f88ae8b8a00afe1ceb20d2fa1e91017b2e7bf01a0c98cb367",
                "md5": "e8c2bdbc37cfa9939527b9337f9abaf1",
                "sha256": "b06c2b5cb3dde2c316d744991120ff7ae132f10052f30421d55c7a04cc742d84"
            },
            "downloads": -1,
            "filename": "uintlib-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e8c2bdbc37cfa9939527b9337f9abaf1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 5533,
            "upload_time": "2025-07-15T14:53:20",
            "upload_time_iso_8601": "2025-07-15T14:53:20.026065Z",
            "url": "https://files.pythonhosted.org/packages/35/9b/6b2d7a033c1f88ae8b8a00afe1ceb20d2fa1e91017b2e7bf01a0c98cb367/uintlib-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "eaf26016508ba191acd7c8de30bb25eee8ddb023dcf97ff3a275ef18d9c58dbb",
                "md5": "8d1f26a9a0a706b4f62d91c922eafd30",
                "sha256": "0496c664f6d8f7db27eea95de0b39481e675dd6a04fe7c28f47dc79e6362b8ec"
            },
            "downloads": -1,
            "filename": "uintlib-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8d1f26a9a0a706b4f62d91c922eafd30",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 5434,
            "upload_time": "2025-07-15T14:53:20",
            "upload_time_iso_8601": "2025-07-15T14:53:20.963663Z",
            "url": "https://files.pythonhosted.org/packages/ea/f2/6016508ba191acd7c8de30bb25eee8ddb023dcf97ff3a275ef18d9c58dbb/uintlib-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-15 14:53:20",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "uintlib"
}
        
Elapsed time: 1.11250s