Better work with hexadecimal numbers
Project description
Hexl Library
Overview
Hexl is a Python library designed to create and manipulate unique hexadecimal IDs. These IDs can be iterated, compared, and used in arithmetic operations. This library includes various methods to generate hexadecimal IDs, convert between decimal and hexadecimal, and perform mathematical operations on these values.
Features
- Hexadecimal ID Generation: Generate random 8-digit hexadecimal IDs.
- Decimal-to-Hexadecimal Conversion: Convert decimal values to their hexadecimal equivalents and vice-versa.
- Iterability: The hexadecimal ID can be iterated over.
- Mathematical Operations: Support for addition, subtraction, multiplication, division, exponentiation, and more with hexadecimal values.
- Comparison Operations: Hexadecimal values can be compared using standard comparison operators.
Class: hexl
Attributes
- hexl_ID: A string representing an 8-digit hexadecimal value. It can be either provided by the user or randomly generated.
Methods
__init__(self, hexl_ID: Union[str, int]): Initializes thehexlinstance with a hexadecimal ID. If no ID is provided, a random one will be generated.generate_hex() -> hexl: Generates a random 8-digit hexadecimal ID.to_hex(values: Union[str, int]) -> str: Converts a decimal or string value into a hexadecimal string.__iter__(): Makes the hexadecimal ID iterable.__repr__(): Returns a string representation of thehexlinstance, showing both the hexadecimal and decimal values.__str__(): Returns the hexadecimal ID as a string.__int__() -> int: Converts the hexadecimal ID to its decimal equivalent.__len__() -> int: Returns the length of the hexadecimal ID.__eq__(self, hex: str) -> bool: Compares the hexadecimal ID with another string for equality.- Mathematical operations:
__add__,__sub__,__mul__,__pow__,__floordiv__,__truediv__for arithmetic operations with hexadecimal values. - Comparison operators:
__le__,__lt__,__ge__,__gt__for comparing hexadecimal values. - Reflexive operations:
__radd__,__rsub__,__rmul__,__rpow__,__rfloordiv__,__rtruediv__for operations where the left-hand side is not ahexlinstance. __hash__(): Returns the hash value of the hexadecimal ID.
Example Usage
from hexl import hexl
# Creating a random hexadecimal ID
hex_instance = hexl()
# Creating a hexadecimal ID from a decimal or string
hex_from_str = hexl("A12FFBD0")
hex_from_int = hexl(12345)
# Performing mathematical operations
result = hex_from_str + 10
result_mul = hex_from_str * 2
# Converting to decimal
decimal_value = int(hex_from_str)
# Comparing hexadecimal IDs
is_equal = hex_instance == "A12FFBD0"
is_greater = hex_instance > hex_from_str
Installation
-
Clone the repository:
git clone https://github.com/username/hexl-library.git
-
Install the required dependencies (if any):
pip install -r requirements.txt
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hexl-1.0.tar.gz.
File metadata
- Download URL: hexl-1.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95999cec46c5d22f310144314e2b96ca3659643c0cf2d1831110b51185b09da7
|
|
| MD5 |
9d6ec65928e00a6d5bd51afadb352f6f
|
|
| BLAKE2b-256 |
0dda0b63844077aa6a413c3a575f36afa295c50a1085e260786fe6c2f18d8a74
|
File details
Details for the file hexl-1.0-py3-none-any.whl.
File metadata
- Download URL: hexl-1.0-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b79847425fa7f26cf6fda2cbd5983d9f7cb70ab9f349ee90e1cc1a4b8d453a5c
|
|
| MD5 |
7c74241bb0e268f2f1c23d735d591f81
|
|
| BLAKE2b-256 |
f8500788f770eff2af7e89b40a7b2890ba1775d28b91751a030b8b764c4f5f81
|