Skip to main content

Small python program that converts base 10 integers or fractionary numbers to bases 2-9 numbers.

Project description

base-converter

Converts base-10 numbers (integers and decimals) to bases 2–9.

Installation

pip install numerical-base-converter-nighthawk017

Usage

As a library

from base_converter import convert_number

convert_number('10', 2)    # '1010'
convert_number('8', 8)     # '10'
convert_number('0.5', 2)   # '0.1'
convert_number('3.14', 8)  # '3.11037...'

As a CLI

base-converter
# Enter the value to convert: 10
# Enter the target base (2-9): 2
# Result: 1010

API

convert_number(value_str: str, target_base: int) -> str

Converts a base-10 number string to the target base. Accepts integers ('42') and decimals ('3.14').

convert_integer_part(value: int, target_base: int) -> str
convert_fractionary_part(value_str: str, target_base: int) -> str

Lower-level functions for converting the integer and fractional parts separately.

Raises ValueError if target_base is outside 2–9 or value_str is not a valid number.

Requirements

Python >= 3.8

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numerical_base_converter-0.0.1-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file numerical_base_converter-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for numerical_base_converter-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f7c8040f66636c539c9d9e1ce6bbb6ef07137d5ee0cb2b15674260c16be5e43
MD5 10b23487d461b3b49ea20b256269596e
BLAKE2b-256 5d44fb5efce75f24e9f3fcee8c2a044b083d5d12fc1ede7d66c340eb35060bb2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page