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.3

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.3
File Size Uploaded Provenance
base_to_base_number-0.0.3.tar.gz 20.0 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 37.3 kB

Release files / base_to_base_number-0.0.3.tar.gz

Download URL base_to_base_number-0.0.3.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
efe5f5d5ff4ca266bb1a1bafc46e5bb7d63b3315590e350838d2dc03847e6025
BLAKE2b-256 checksum
How to use checksums
787de4687e9beaf53d224f652ffbbfa1f3d7b0ce6eff1bc9fc9fa577a9a009d7
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.3-py3-none-any.whl

Download URL base_to_base_number-0.0.3-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08d744fe16d38b607fe68ad945683d5d4766b4a600b392665f3c79a1c55d0177
BLAKE2b-256 checksum
How to use checksums
45016b7daf06b08e6e8270aa9097089203ec308034edc54f4932b73733f14648
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.3

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