digit_converter


Namedigit_converter JSON
Version 2.3 PyPI version JSON
download
home_pagehttps://github.com/Freakwill/digit-converter
SummaryA 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`.
upload_time2025-08-26 09:51:30
maintainerNone
docs_urlNone
authorNone
requires_python<4.0,>=3.9
licenseMIT
keywords digit converting encoding genetic algorithm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # 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

```python
import digit_converter
```

### Basic usage

```pyhon
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}


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Freakwill/digit-converter",
    "name": "digit_converter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "Digit Converting, Encoding, Genetic Algorithm",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/9b/67/488034acbc6d526d6a15c7ba55a3c01725aeb410b2b4b77eefaa01aba3b9/digit_converter-2.3.tar.gz",
    "platform": null,
    "description": "# digit_converter\n\nA 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`. \ud83d\udd22\n\n## Abstract\n\nA cool tool for digits converting. It transforms a number to a list and verse vice, such as represent a number by a binary list.\nIt could be applied in GA.\n\n**Keywords** Converter, Digits\n\n## Classes and Objects\n\nClasses:\n```\n    BaseConverter: \n        .tonumber(lst), .tolist(num, L)\n        \n    DigitConverter:\n    BinaryConverter: subclass of DigitConverter\n    IntervalConverter\n```\nObjects:\n```\n    colorConverter: instance of BinaryConverter\n    unitIntervalConverter: instance of IntervalConverter  == IntervalConverter(lb=0, ub=1)\n```\n\n## Grammar\nInstall the lib, by `pip install digit_converter`\n\n### Import\n\n```python\nimport digit_converter\n```\n\n### Basic usage\n\n```pyhon\nprint('=*= Example 1 =*=')\nprint(f'color-converter: {colorConverter.tonumber([1,0,1,0,1,1,1,0])}<->{colorConverter.tolist(174)}')\n\nprint('=*= Example 2 =*=')\nc = BinaryConverter(exponent=3)\nd = c.tolist(12.223, L=8)\nprint(f'binary-converter: {d}<->{c.tonumber(d)}={c.pretty(d)}')\ni, f = c.seperate(12.223, L=8)\nprint(f'integer part: {i}, fractional part: {f}')\n\nprint('=*= Example 3 =*=')\nc = IntervalConverter(lb=0, ub=10)\nd = c.tolist(2.4, L=8)\nprint(f'[{c.lb},{c.ub}]-converter: {d}<->{c(d)} -> {c.pretty(d)}-th number')\n\nprint('=*= Example 4 =*=')\nc = DigitConverter(base=16)\nd = c.tolist(2.4, L=8)\nprint(f'16-converter: {d}<->{c(d)}={c.pretty(d)}')\n```\n\nOUTPUT::\n\n    =*= Example 1 =*=\n    color-converter: 174<->[1, 0, 1, 0, 1, 1, 1, 0]\n    =*= Example 2 =*=\n    binary-converter: [1, 1, 0, 0, 0, 0, 1, 1]<->12.1875=2^{3} + 2^{2} + 2^{-3} + 2^{-4}\n    integer part: [1, 1, 0, 0], fractional part: [0, 0, 1, 1]\n    =*= Example 3 =*=\n    [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\n    =*= Example 4 =*=\n    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}\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "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`.",
    "version": "2.3",
    "project_urls": {
        "Homepage": "https://github.com/Freakwill/digit-converter",
        "Repository": "https://github.com/Freakwill/digit-converter"
    },
    "split_keywords": [
        "digit converting",
        " encoding",
        " genetic algorithm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f021a312171aa45a0b65e6106dccfa2f33cb3c39a207302902337d24f38eb654",
                "md5": "98aff28539dc63917171175a59d8d9a6",
                "sha256": "af22c65dd51db81bacab722a6a277762b0b8837650f416597ae3dfcd1bef5b11"
            },
            "downloads": -1,
            "filename": "digit_converter-2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "98aff28539dc63917171175a59d8d9a6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 5420,
            "upload_time": "2025-08-26T09:51:24",
            "upload_time_iso_8601": "2025-08-26T09:51:24.869176Z",
            "url": "https://files.pythonhosted.org/packages/f0/21/a312171aa45a0b65e6106dccfa2f33cb3c39a207302902337d24f38eb654/digit_converter-2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9b67488034acbc6d526d6a15c7ba55a3c01725aeb410b2b4b77eefaa01aba3b9",
                "md5": "8cd51bb92c5f915c56fa5a546be8ae6f",
                "sha256": "c51d303478fd2e4c60d920630274b4153e1f5f6aa1f2f80e94773e1d60e0f678"
            },
            "downloads": -1,
            "filename": "digit_converter-2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "8cd51bb92c5f915c56fa5a546be8ae6f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 4759,
            "upload_time": "2025-08-26T09:51:30",
            "upload_time_iso_8601": "2025-08-26T09:51:30.059678Z",
            "url": "https://files.pythonhosted.org/packages/9b/67/488034acbc6d526d6a15c7ba55a3c01725aeb410b2b4b77eefaa01aba3b9/digit_converter-2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-26 09:51:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Freakwill",
    "github_project": "digit-converter",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "digit_converter"
}
        
Elapsed time: 1.05375s