Base to Base Number
base_to_base_number is a lightweight Python package for converting numbers from one base to another. It supports bases from 2 to 36, handles positive and negative numbers, and processes both integers and fractions.
Example
A live representation of this package in action is my base number calculator -> NumberConverter
Features
- Wide Base Support: Convert numbers between any arbitrary bases from 2 up to 36.
- Signed Numbers: Fully supports positive (
+) and negative (-) numbers. - Fractions Supported: Handles fractional numbers with customizable precision.
- Pure Python: Lightweight implementation with zero external dependencies.
Installation
You can install the package using pip:
pip install base-to-base-number
Usage
Here is a quick example of how to use BaseNumber to parse and convert numbers across different bases:
from base_to_base_number import BaseNumber
# Initialize a number in base 16 (Hexadecimal)
# You can pass a string representation including signs (+/-) and fractions
num = BaseNumber("-1A.8", base=16)
# Convert to base 10
decimal_result = num.convert_to(10)
print(f"Base 10: {decimal_result}") # Output: -26.50 (approximate fraction handling)
# Convert to base 2 (Binary)
binary_result = num.convert_to(2, precision=4)
print(f"Base 2: {binary_result}")
API Reference
BaseNumber(number_str: str, base: int = 10)
Initializes a number object.
number_str: A string representing the number (e.g.,"1010","FF.EE","-45.2").base: The base of the input number (must be between 2 and 36, default is 10).
Methods
convert_to(base: int, precision: int = 2) -> str: Converts the stored number to a target base with a specified fractional precision.get_number() -> float: Returns the internal numerical representation (base 10 equivalent).get_integer() -> int: Returns the integer portion of the number, base 10.get_fraction() -> float: Returns the fractional portion of the number, base 10.get_integer_raw() -> str: Returns the origianl integer portion of the number via string.get_fraction_raw() -> str: Returns the original fractional portion of the number via string.
Requirements
- Python
3.10or higher.
License
This project is licensed under the terms of the MIT License.
Metadata
Release files for base-to-base-number 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| base_to_base_number-0.0.1.tar.gz | 20.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| base_to_base_number-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.3 kB
Release files / base_to_base_number-0.0.1.tar.gz
| Download URL | base_to_base_number-0.0.1.tar.gz |
|---|---|
| Size | 20.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f0354a5f244cbebfc08269d1a3397295bc1e2394164ed58dcfbd020223b1709
|
|
BLAKE2b-256 checksum How to use checksums |
fe33ed4a002bfe76b2b80d4f54b4ac40dc7de7846533625e8dcb254aee9d3d65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / base_to_base_number-0.0.1-py3-none-any.whl
| Download URL | base_to_base_number-0.0.1-py3-none-any.whl |
|---|---|
| Size | 17.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
499efe7437703c0018641e8bd3a0800f578ee821e583fc3aa42e0fec13add3ab
|
|
BLAKE2b-256 checksum How to use checksums |
25c66bd7fc53a841a4451b7dc09d4f30ab55d370abd97b0daab89b4f18e27aca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for base-to-base-number 0.0.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.