Skip to main content

Number Radix

This is a Python script and library to encode, decode and format numbers including fractions and exponential notation in radixes/bases other than decimal, such as octal, dozenal/duodecimal, hexadecimal, base57 and base62. The radix can also be determined by any number of digits specified: 0123456789ab...

Requirements

  • Python 3

Installation

From the Python Package Index:

pip install num-radix

Or download and run:

python3 setup.py install

Command-Line

Use the --help argument for help.

num-radix --help

By default, the script encodes and decodes in dozenal.

This outputs '6X,534;3000' encoded in dozenal.

num-radix --encode 142456.25 --format ',.4f'

The format string causes the output to have a scale of 4 and every 3 integer digits to be separated by a comma. The format is given in Python format string syntax.

Format with e-notation. This outputs '4;133X82e-0E'.

num-radix --encode 0.000000000005526745 --format '.6e'

Encode in hexadecimal.

num-radix --encode 142 --base hex

Decode back to a decimal from dozenal.

num-radix --decode '6X534;3'

The input and output can be piped. Each line of input is encoded (or decoded) and output on a new line.

echo -e "142\n4353" | num-radix --encode - | cat

Python

Import the library.

from num_radix import Radix

Create a radix.

dozenal = Radix.dozenal()
hexa = Radix.hex()
base20 = Radix("0123456789ABCDEFGHIJ", sep="|")

Encode with the radix object.

dozenal.encode(3546)
dozenal.encode(142456.25, "013.4f")
numbers = [142456.25, 34, 0.000345]
"These numbers {:013.4f}, {}, {:e} are in dozenal".format(*dozenal.wrap(numbers))

Encoding date & time.

from datetime import datetime
now = datetime.now()
dozenal_now = dozenal.wrap(now.timetuple()[:6])
"{}-{:02}-{:02} {:02}:{:02}:{:02}".format(*dozenal_now)

Decode with the radix object.

dozenal.decode("6X534;3")

There are more examples in the demo section at the end of the __init__.py file.

Metadata

Release files for num-radix 1.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 num-radix 1.0.2
File Size Uploaded
num-radix-1.0.2.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for num-radix 1.0.2
File Interpreter ABI Platform
num_radix-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / num-radix-1.0.2.tar.gz

Download URL num-radix-1.0.2.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
eba165c958faa92e979ddfe82089055dc22da852625385849bc0855d3f0d92a0
BLAKE2b-256 checksum
How to use checksums
f7cddf880fabb8eaddbda9bdfc29562d7aef91b91d40270e7b808656e00fbef8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6

Release files / num_radix-1.0.2-py3-none-any.whl

Download URL num_radix-1.0.2-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c58d821a45d7f1707fd389cd32b9dbd7affbd3ee317d458a59be63e1ef06e9b
BLAKE2b-256 checksum
How to use checksums
7c59d988aeec4471a2e6c1a19961a8d134a4403b96df2f79658262a9aff6f588
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

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