A cool tool for digits converting. It could be applied in GA. It transforms a number to a list of digits under any base.
Project description
Introduction
Abstract
A cool tool for digits converting.
It could be applied in Genetic Algorithm to encode the solutions.
Keywords Converter, Digits
Content
Classes
BaseConverter: .tonumber(lst), .tolist(num, L)
DigitConverter
BinaryConverter: subclass of DigitConverter
IntegerConverter: only convert integer
IntervalConverter: subclass of IntegerConverter, converts a number in an interval to an integer what is the index of the number then applies IntegerConverter
Objects
colorConverter: instance of BinaryConverter, transform a number (0~255) to a 8-length list of 0-1s
unitIntervalConverter: instance of IntervalConverter, transform a number in interval [0,1] to list of 0-1s
Grammar
import
import digit_converter
Basic usage
Codes
print(f'color-converter: {colorConverter.tonumber([1,0,1,0,1,1,1,0])}<->{colorConverter.tolist(174)}')
c = BinaryConverter(exponent=3)
d = c.tolist(12.223, L=8)
print(f'binary-converter: {d}<->{c.tonumber(d)}={c.pretty(d)}')
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')
c = DigitConverter(base=16)
d = c.tolist(2.4, L=8)
print(f'16-converter: {d}<->{c(d)}={c.pretty(d)}')
OUTPUT:
color-converter: 174<->[1, 0, 1, 0, 1, 1, 1, 0]
binary-converter: [1, 1, 0, 0, 0, 0, 1, 1]<->12.1875=2^{3} + 2^{2} + 2^{-3} + 2^{-4}
[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
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
Project details
Release history Release notifications | RSS feed
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.0.tar.gz
(4.3 kB
view details)
Built Distribution
File details
Details for the file digit_converter-2.0.tar.gz
.
File metadata
- Download URL: digit_converter-2.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.11 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 840ad9810b2797ef54245b693b21b7d1cd0538b40cef888569651a42fa757320 |
|
MD5 | 54e3bb59de274702914b47ffcc0b6247 |
|
BLAKE2b-256 | 62ef95a35534112d9de76f905f1e6bd237bea285b72690a9bb8a4f17947dc5d4 |
File details
Details for the file digit_converter-2.0-py3-none-any.whl
.
File metadata
- Download URL: digit_converter-2.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.11 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a67712c87be556e2428901c39694cfa8e17384c252fdf302fc2e207df40677c |
|
MD5 | 9c64db63c3876f3693d8b1a1bcad38aa |
|
BLAKE2b-256 | 1ab1dab8b120793111f9b970beaf4654a95dda51b1a664eeb34b03ee8dc6347e |