digit_converter
A useful tool for digit conversion, applicable in Genetic Algorithms (GA). It transforms a number into a list of digits under any base, for example, [1, 0, 1, 0, 1, 1, 1, 0] <-> 174. 🔢
Abstract
A cool tool for digits converting. It transforms a number to a list and verse vice, such as represent a number by a binary list. It could be applied in GA.
Keywords Converter, Digits
Classes and Objects
Classes:
BaseConverter:
.tonumber(lst), .tolist(num, L)
DigitConverter:
BinaryConverter: subclass of DigitConverter
IntervalConverter
Objects:
colorConverter: instance of BinaryConverter
unitIntervalConverter: instance of IntervalConverter == IntervalConverter(lb=0, ub=1)
Grammar
Install the lib, by pip install digit_converter
Import
import digit_converter
Basic usage
print('=*= Example 1 =*=')
print(f'color-converter: {colorConverter.tonumber([1,0,1,0,1,1,1,0])}<->{colorConverter.tolist(174)}')
print('=*= Example 2 =*=')
c = BinaryConverter(exponent=3)
d = c.tolist(12.223, L=8)
print(f'binary-converter: {d}<->{c.tonumber(d)}={c.pretty(d)}')
i, f = c.seperate(12.223, L=8)
print(f'integer part: {i}, fractional part: {f}')
print('=*= Example 3 =*=')
c = IntervalConverter(lb=0, ub=10)
d = c.tolist(2.4, L=8)
print(f'[{c.lb},{c.ub}]-converter: {d}<->{c(d)} -> {c.pretty(d)}-th number')
print('=*= Example 4 =*=')
c = DigitConverter(base=16)
d = c.tolist(2.4, L=8)
print(f'16-converter: {d}<->{c(d)}={c.pretty(d)}')
OUTPUT::
=*= Example 1 =*=
color-converter: 174<->[1, 0, 1, 0, 1, 1, 1, 0]
=*= Example 2 =*=
binary-converter: [1, 1, 0, 0, 0, 0, 1, 1]<->12.1875=2^{3} + 2^{2} + 2^{-3} + 2^{-4}
integer part: [1, 1, 0, 0], fractional part: [0, 0, 1, 1]
=*= Example 3 =*=
[0,10]-converter: [0, 0, 1, 1, 1, 1, 0, 1]<->2.3828125 -> 2^{5} + 2^{4} + 2^{3} + 2^{2} + 2^{0}-th number
=*= Example 4 =*=
16-converter: [0, 2, 6, 6, 6, 6, 6, 6]<->2.399999976158142=2*16^{0} + 6*16^{-1} + 6*16^{-2} + 6*16^{-3} + 6*16^{-4} + 6*16^{-5} + 6*16^{-6}
Release files for digit_converter 2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| digit_converter-2.3.tar.gz | 4.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| digit_converter-2.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.2 kB
Release files / digit_converter-2.3.tar.gz
| Download URL | digit_converter-2.3.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c51d303478fd2e4c60d920630274b4153e1f5f6aa1f2f80e94773e1d60e0f678
|
|
BLAKE2b-256 checksum How to use checksums |
9b67488034acbc6d526d6a15c7ba55a3c01725aeb410b2b4b77eefaa01aba3b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.13.5 Darwin/24.2.0
|
Release files / digit_converter-2.3-py3-none-any.whl
| Download URL | digit_converter-2.3-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af22c65dd51db81bacab722a6a277762b0b8837650f416597ae3dfcd1bef5b11
|
|
BLAKE2b-256 checksum How to use checksums |
f021a312171aa45a0b65e6106dccfa2f33cb3c39a207302902337d24f38eb654
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.13.5 Darwin/24.2.0
|