baseconvert


Namebaseconvert JSON
Version 2.0.4 PyPI version JSON
download
home_pagehttps://github.com/BreadMakesYouFull/baseconvert.git
SummaryConvert numbers between bases.
upload_time2024-08-25 02:29:24
maintainerNone
docs_urlNone
authorsqudle, BreadMakesYouFull
requires_pythonNone
licenseMIT
keywords base bases radix numeral system number hex dec bin hexidecimalbinary decimal fraction fractions integer convert gui
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            baseconvert
===========

Convert any rational number, from any (positive integer) base, to any
(positive integer) base. Output numbers as tuple or string.

-  Any rational number
-  Arbitrary precision
-  Fractions
-  Recurring/repeating fractional digits.
-  Input numbers as tuple or string or number.
-  Output numbers as tuple or string.

MIT License (MIT) Copyright (c) 2024 BreadMakesYouFull
MIT License (MIT) Copyright (c) 2016 squdle

`github <https://github.com/BreadMakesYouFull/baseconvert>`__

Requires
--------

-  Python 3

Install / Uninstall
-------------------

Install:

::

    pip install baseconvert

Optionally install GUI frontend and launch:

::

    # Install with pyside6
    pip install baseconvert[gui]
    # Run GUI frontend
    baseconvert

Uninstall:

::

    pip uninstall baseconvert

Quickstart
----------

::

    # base(number, input_base, output_base)

    >>> base((15, 15, 0, ".", 8), 16, 10)
    (4, 0, 8, 0, '.', 5)

    >>> base("FF0.8", 16, 10, string=True)
    '4080.5'

    >>> base("4080.5", 10, 16, string=True)
    'FF0.8'

Or from command line

::

     $ echo 4080.5 | python -m baseconvert -i 10 -o 16
     FF0.8

     $ python -m baseconvert -n 4080.5 -i 10 -o 16
     FF0.8

Tuple representation
--------------------

Numbers are represented as a sequence of digits. Each digit is a base-10
integer value. The radix point, which separates the integer and
fractional parts, is denoted by a string period.

::

     (int, int, int, ... , '.', ... , int, int, int)
     (   integer part    , '.',  fractional part   )

String representation
---------------------

String digits (after z the values are in ascending Unicode):

::

    0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

    |  Value  | Representation |
    |---------|----------------|
    |  0 -  9 |    0  -  9     |
    | 10 - 53 |    A  -  Z     |
    | 36 - 61 |    a  -  z     |
    | 62 +    | unicode 123 +  |

    For bases higher than 61 it's recommended to use tuple representation.

Examples
--------

::

    # base(number, input_base, output_base)
    >>> n = (15,15,".",0,8)
    >>> base(n, 16, 10)
    (2, 5, 5, '.', 0, 3, 1, 2, 5)
    >>> base(n, 16, 10, string=True)
    '255.03125'

    >>> base("FF.08", 16, 10) == base((15,15,".",0,8), 16, 10)
    True

    # A callable BaseConverter object can also be created.
    # This is useful for when several numbers need to be converted.

    >>> b = BaseConverter(input_base=16, output_base=8)
    >>> b("FF")
    (3, 7, 7)
    >>> b((15, 15))
    (3, 7, 7)
    >>> b("FF") == b((15,15))
    True

    >>> base(0.1, 3, 10, string=True)
    '0.[3]'

Recurring digits
~~~~~~~~~~~~~~~~

Recurring digits at the end of a fractional part will be enclosed by "["
and "]" in both string and tuple representation. This behavior can be
turned off by setting the recurring argument of base or BaseConverter
object to False.

::

    >>> base("0.1", 3, 10, string=True)
    '0.[3]'
    >>> base("0.1", 3, 10, string=True, recurring=False)
    '0.3333333333'

Max fractional depth
~~~~~~~~~~~~~~~~~~~~

Integer parts are always of arbitrary size. Fractional depth (number of
digits) can must be specified by setting the max\_depth argument of base
or a BaseConverter object (default 10).

::

    >>> base("0.2", 10, 8)
    (0, '.', 1, 4, 6, 3, 1, 4, 6, 3, 1, 4)
    >>> base("0.2", 10, 8, max_depth=1)
    (0, '.', 1)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/BreadMakesYouFull/baseconvert.git",
    "name": "baseconvert",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "base bases radix numeral system number hex dec bin hexidecimalbinary decimal fraction fractions integer convert gui",
    "author": "squdle, BreadMakesYouFull",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/a7/5e/95d4242f08306c18d323dfd60eb891eab264f700e28d7e2f04a308e2ad07/baseconvert-2.0.4.tar.gz",
    "platform": null,
    "description": "baseconvert\n===========\n\nConvert any rational number, from any (positive integer) base, to any\n(positive integer) base. Output numbers as tuple or string.\n\n-  Any rational number\n-  Arbitrary precision\n-  Fractions\n-  Recurring/repeating fractional digits.\n-  Input numbers as tuple or string or number.\n-  Output numbers as tuple or string.\n\nMIT License (MIT) Copyright (c) 2024 BreadMakesYouFull\nMIT License (MIT) Copyright (c) 2016 squdle\n\n`github <https://github.com/BreadMakesYouFull/baseconvert>`__\n\nRequires\n--------\n\n-  Python 3\n\nInstall / Uninstall\n-------------------\n\nInstall:\n\n::\n\n    pip install baseconvert\n\nOptionally install GUI frontend and launch:\n\n::\n\n    # Install with pyside6\n    pip install baseconvert[gui]\n    # Run GUI frontend\n    baseconvert\n\nUninstall:\n\n::\n\n    pip uninstall baseconvert\n\nQuickstart\n----------\n\n::\n\n    # base(number, input_base, output_base)\n\n    >>> base((15, 15, 0, \".\", 8), 16, 10)\n    (4, 0, 8, 0, '.', 5)\n\n    >>> base(\"FF0.8\", 16, 10, string=True)\n    '4080.5'\n\n    >>> base(\"4080.5\", 10, 16, string=True)\n    'FF0.8'\n\nOr from command line\n\n::\n\n     $ echo 4080.5 | python -m baseconvert -i 10 -o 16\n     FF0.8\n\n     $ python -m baseconvert -n 4080.5 -i 10 -o 16\n     FF0.8\n\nTuple representation\n--------------------\n\nNumbers are represented as a sequence of digits. Each digit is a base-10\ninteger value. The radix point, which separates the integer and\nfractional parts, is denoted by a string period.\n\n::\n\n     (int, int, int, ... , '.', ... , int, int, int)\n     (   integer part    , '.',  fractional part   )\n\nString representation\n---------------------\n\nString digits (after z the values are in ascending Unicode):\n\n::\n\n    0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n\n    |  Value  | Representation |\n    |---------|----------------|\n    |  0 -  9 |    0  -  9     |\n    | 10 - 53 |    A  -  Z     |\n    | 36 - 61 |    a  -  z     |\n    | 62 +    | unicode 123 +  |\n\n    For bases higher than 61 it's recommended to use tuple representation.\n\nExamples\n--------\n\n::\n\n    # base(number, input_base, output_base)\n    >>> n = (15,15,\".\",0,8)\n    >>> base(n, 16, 10)\n    (2, 5, 5, '.', 0, 3, 1, 2, 5)\n    >>> base(n, 16, 10, string=True)\n    '255.03125'\n\n    >>> base(\"FF.08\", 16, 10) == base((15,15,\".\",0,8), 16, 10)\n    True\n\n    # A callable BaseConverter object can also be created.\n    # This is useful for when several numbers need to be converted.\n\n    >>> b = BaseConverter(input_base=16, output_base=8)\n    >>> b(\"FF\")\n    (3, 7, 7)\n    >>> b((15, 15))\n    (3, 7, 7)\n    >>> b(\"FF\") == b((15,15))\n    True\n\n    >>> base(0.1, 3, 10, string=True)\n    '0.[3]'\n\nRecurring digits\n~~~~~~~~~~~~~~~~\n\nRecurring digits at the end of a fractional part will be enclosed by \"[\"\nand \"]\" in both string and tuple representation. This behavior can be\nturned off by setting the recurring argument of base or BaseConverter\nobject to False.\n\n::\n\n    >>> base(\"0.1\", 3, 10, string=True)\n    '0.[3]'\n    >>> base(\"0.1\", 3, 10, string=True, recurring=False)\n    '0.3333333333'\n\nMax fractional depth\n~~~~~~~~~~~~~~~~~~~~\n\nInteger parts are always of arbitrary size. Fractional depth (number of\ndigits) can must be specified by setting the max\\_depth argument of base\nor a BaseConverter object (default 10).\n\n::\n\n    >>> base(\"0.2\", 10, 8)\n    (0, '.', 1, 4, 6, 3, 1, 4, 6, 3, 1, 4)\n    >>> base(\"0.2\", 10, 8, max_depth=1)\n    (0, '.', 1)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Convert numbers between bases.",
    "version": "2.0.4",
    "project_urls": {
        "Homepage": "https://github.com/BreadMakesYouFull/baseconvert.git"
    },
    "split_keywords": [
        "base",
        "bases",
        "radix",
        "numeral",
        "system",
        "number",
        "hex",
        "dec",
        "bin",
        "hexidecimalbinary",
        "decimal",
        "fraction",
        "fractions",
        "integer",
        "convert",
        "gui"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b85d615ca48e2ca46f3e0656ab57c98ee6a9ce444a4c514e82a35fb0b07b5ce2",
                "md5": "84fe32144b06fe3b90ff01af779d2396",
                "sha256": "32ebaedefc6726362c104069adebd5c7a3126dbcf982a5da8c729e79ccb93553"
            },
            "downloads": -1,
            "filename": "baseconvert-2.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "84fe32144b06fe3b90ff01af779d2396",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 14410,
            "upload_time": "2024-08-25T02:29:23",
            "upload_time_iso_8601": "2024-08-25T02:29:23.446067Z",
            "url": "https://files.pythonhosted.org/packages/b8/5d/615ca48e2ca46f3e0656ab57c98ee6a9ce444a4c514e82a35fb0b07b5ce2/baseconvert-2.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a75e95d4242f08306c18d323dfd60eb891eab264f700e28d7e2f04a308e2ad07",
                "md5": "7b743b8aac3bb9e783ada5121eaa6230",
                "sha256": "06283fd418becc29b7b6420c983780f06f6f3a727f4cc4a4466d2de69c0230b1"
            },
            "downloads": -1,
            "filename": "baseconvert-2.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "7b743b8aac3bb9e783ada5121eaa6230",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 14198,
            "upload_time": "2024-08-25T02:29:24",
            "upload_time_iso_8601": "2024-08-25T02:29:24.839221Z",
            "url": "https://files.pythonhosted.org/packages/a7/5e/95d4242f08306c18d323dfd60eb891eab264f700e28d7e2f04a308e2ad07/baseconvert-2.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-25 02:29:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "BreadMakesYouFull",
    "github_project": "baseconvert",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "baseconvert"
}
        
Elapsed time: 4.77001s