Number Conversion
This package allows you to convert a number between any of the 82 standard bases described by Wikipedia and here. It provides both commandline options and in code options to convert.
In Command Line
There are several ways to use from command line with python -m convert_numbers.* command.
a) convert_numbers.convert
python -m convert_numbers.convert number new_base --current_base python -m convert_numbers.convert number new_base -cb python -m convert_numbers.convert 12 2 -cb 10
b) convert_numbers.loop
This converts the input and waits for more input to convert until it’s quit. The user types in 3 numbers separated by a space.
number_to_convert base_to_convert_to current_base
If current_base is not provided base 10 is assumed. Runs until user types ‘q’. For help type ‘h’.
python -m convert_numbers.loop Enter 'number new_base current_base': number new_base current_base* Enter 'number new_base current_base': 12 2 10* '12' in Decimal (base 10) to Binary (base 2) = '1100' Enter 'number new_base current_base': q
c) convert_numbers.table
python -m convert_numbers.table 12,13,14 2 -cb=16 Base 16 to base 2 ---------------------------- | Hexadecimal | Binary | ---------------------------- | 12 | 10010 | | 13 | 10011 | | 14 | 10100 | ----------------------------
An example of input file is found here.
d) convert_numbers.file
This takes input completely from a file and outputs to another file. In the file, the first line is the list of comma-separated numbers to convert, the second is the new base, while the third is the current base, if any otherwise it’s base 10. Example input is here
python -m convert_numbers.file input_file.txt output_file.txt Written to 'out_file.txt'
Writes a csv like file, two columns old number, new number. The first two rows are informational.
In python code
Several functions are described by the package. They are convert_number, convert_from_base_10, convert_float_from_base_10, convert_to_base_10 and convert_float_to_base_10. To check user input refer to this section
Main Functions
These, only one, can be used in isolation to convert a number from any base to any other base.
1. convert_number
Usage
from conversions import convert_number
convert_number('12', 10, 2) # return '1100'
Helper Functions
1. convert_from_base_10
Usage
from conversions.convert import convert_from_base_10
result = convert_from_base_10(12, 2) # returns ['1100', 2]
2. convert_float_from_base_10
Usage
from conversions.convert import convert_float_from_base_10
result = convert_float_from_base_10(0.25, 2) # ['0.01', 2]
3. convert_to_base_10
from conversions.convert import convert_to_base_10
result = convert_to_base_10('1001', 2) # returns 9
4. convert_float_to_base_10
from conversions.convert import convert_float_to_base_10
result = convert_float_to_base_10('0.2', 16) # returns 0.125
Utility functions
To check the name of a base given the base, use n_utils.base_find which takes the base as argument and returns a string of the name of the base.
from n_utils import base_find, ensure_base_is_standard, base_limits
ensure_base_is_standard(63) # False
ensure_base_is_standard(64) # True
base_limits('G4', 16) # False
base_limits('G4', 20) # True
base_find(2) # Binary
base_find(10) # Decimal
Metadata
Release files for number-conversions 0.0.7
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 | Actions |
|---|---|---|---|---|
| number-conversions-0.0.7.tar.gz | 58.2 kB | Without provenance | Details for number-conversions-0.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| number_conversions-0.0.7-py3-none-any.whl | Python 3 | none | any | Details for number_conversions-0.0.7-py3-none-any.whl |
Total release size: 117.8 kB
Release files / number-conversions-0.0.7.tar.gz
| Download URL | number-conversions-0.0.7.tar.gz |
|---|---|
| Size | 58.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
46cc271672331026a49de5e6912d22654c31f6a7ebe3957a60eb5a4a9aa5861c
|
|
BLAKE2b-256 checksum How to use checksums |
73de21df0b1066c14c6bb68f28413ec5d15b8b30f4e57b5bdc30ccddaa5f4271
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.0
|
Release files / number_conversions-0.0.7-py3-none-any.whl
| Download URL | number_conversions-0.0.7-py3-none-any.whl |
|---|---|
| Size | 59.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f4bdf3293595562b39e051a62dc9a1928cae92b683af5774c0706bece2cc8683
|
|
BLAKE2b-256 checksum How to use checksums |
c1b6474c52810b14ff376fc7a9c802dfc01ef06c1185994da7df330c6b21d716
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.0
|
Security for number-conversions 0.0.7
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.