Skip to main content

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}

Download files

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

Source Distribution

digit_converter-2.3.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

digit_converter-2.3-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file digit_converter-2.3.tar.gz.

File metadata

  • Download URL: digit_converter-2.3.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.13.5 Darwin/24.2.0

File hashes

Hashes for digit_converter-2.3.tar.gz
Algorithm Hash digest
SHA256 c51d303478fd2e4c60d920630274b4153e1f5f6aa1f2f80e94773e1d60e0f678
MD5 8cd51bb92c5f915c56fa5a546be8ae6f
BLAKE2b-256 9b67488034acbc6d526d6a15c7ba55a3c01725aeb410b2b4b77eefaa01aba3b9

See more details on using hashes here.

File details

Details for the file digit_converter-2.3-py3-none-any.whl.

File metadata

  • Download URL: digit_converter-2.3-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.13.5 Darwin/24.2.0

File hashes

Hashes for digit_converter-2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 af22c65dd51db81bacab722a6a277762b0b8837650f416597ae3dfcd1bef5b11
MD5 98aff28539dc63917171175a59d8d9a6
BLAKE2b-256 f021a312171aa45a0b65e6106dccfa2f33cb3c39a207302902337d24f38eb654

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.3 This release

2 files

2.2

2 files

2.0

2 files

Supported by

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