Skip to main content

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.main 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.10 or higher.

License

This project is licensed under the terms of the MIT License.

Metadata

Release files for base-to-base-number 0.0.2

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

Source distribution (sdist)

Source distribution for base-to-base-number 0.0.2
File Size Uploaded Provenance
base_to_base_number-0.0.2.tar.gz 20.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for base-to-base-number 0.0.2
File Interpreter ABI Platform
base_to_base_number-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 37.3 kB

Release files / base_to_base_number-0.0.2.tar.gz

Download URL base_to_base_number-0.0.2.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cec57ab680e76e3d169f14703d1c86e2ef349627d6d0a1464abd9bfb58331952
BLAKE2b-256 checksum
How to use checksums
a3029f71779497a1bffc763e02eb6b9e55cb2ec76de3659f1ed15c1838279e65
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.2-py3-none-any.whl

Download URL base_to_base_number-0.0.2-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcea34cade8243c878c17b9c855a60e18897ad4f4e0b328ea25ea4eef5d206bb
BLAKE2b-256 checksum
How to use checksums
3d0410fd202868619041c6fc5bb1e7b8c39e97f6640d05d7d1c06e37aaa32066
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.2

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.

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