Skip to main content

a LIBrary implementing TGMK (Tebi-Gibi-Mebi-Kibi), a human-readable 1024-base integer representation, suitable for bits and bytes

Project description

INSTALLATION

    $ pip3 install libtgmk

HELP

    $ pydoc libtgmk

NAME

    libtgmk - a LIBrary implementing TGMK (Tebi-Gibi-Mebi-Kibi), a human-readable 1024-base integer representation, suitable for bits and bytes

DESCRIPTION

    A "TGMK literal" is a string made by:

        • zero or more leading blanks
        • an optional ('+' or '-') "sign"
        • one or more "1024-base-digits", each made by:
            • a "coefficient", an unsigned decimal integer constant, as '0', '1' or '10000'
            • a "scale factor", a letter in 'KMGTPEZYkmgtpezy')
        • zero or more trailing blanks

    Letters have the following well-known meanings:

        ╔══════╤══════╤════╤══════════════════╤═══════╤═════════════════════════╗
        ║LETTER│PREFIX│LOG2│      LOG10       │LOG1024│          VALUE          ║
        ╟──────┼──────┼────┼──────────────────┼───────┼─────────────────────────╢
        ║K/k   │kibi- │  10│ 3.010299956639812│      1│                     1024║
        ║M/m   │mebi- │  20│ 6.020599913279624│      2│                  1048576║
        ║G/g   │gibi- │  30│ 9.030899869919436│      3│               1073741824║
        ║T/t   │tebi- │  40│12.041199826559248│      4│            1099511627776║
        ║P/p   │pebi- │  50│ 15.05149978319906│      5│         1125899906842624║
        ║E/e   │exbi- │  60│ 18.06179973983887│      6│      1152921504606846976║
        ║Z/z   │zebi- │  70│21.072099696478684│      7│   1180591620717411303424║
        ║Y/y   │yobi- │  80│24.082399653118497│      8│1208925819614629174706176║
        ╚══════╧══════╧════╧══════════════════╧═══════╧═════════════════════════╝

    Only the last 1024-base-digit may lack the letter, meaning unities.

    Scale factor letters must appear left to right in strictly decreasing order:

        • '3m5k7' is ok, its value is 3 * 1024 ** 2 + 5 * 1024 + 7 = 3150855
        • '5k3m7' is wrong
        • '5k3k7' is wrong too

    In coefficients one or more leading zeros are allowed, while commas are not:

        • '04096m' is ok
        • '4,096m' is wrong

    A TGMK literal is "normalized" if:

        • no leading or trailing blanks are present
        • sign is '-' for negative numbers, absent for zero or positive numbers
        • coefficients are between 1 and 1023, with no leading zeros, with two exceptions:
            • normalized TGMK literal for zero is '0'
            • for very large numbers the coefficient preceding 'Y' can get any value
        • scale factor letters are always uppercase

    TGMK format is implemented by two functions, tgmk2int() and int2tgmk(), both allowing
    str or int arguments. So, if s is a str containing a TGMK literal (normalized
    or not) and i is an int, then:

        • tgmk2int(s) returns s converted to int
        • tgmk2int(i) returns i unchanged
        • int2tgmk(i) returns i converted to a str in normalized TGMK format
        • int2tgmk(s) returns s translated as a str in normalized TGMK format

    Usage:

        >>> from libtgmk import tgmk2int, int2tgmk

PACKAGE CONTENTS



FUNCTIONS

    int2tgmk(x=0)
        x can be int or str, if x is int then it's converted into normalized TGMK format:

            >>> int2tgmk(-3000 * 1024 - 1)
            '-2M952K1'

        else if x is str then it must be a TGMK literal (normalized or not) and it's converted
        from TGMK into int and back from int into TGMK normalized format:

            >>> int2tgmk('-3000k1')
            '-2M952K1'

        If argument is not given then result is '0'.

    tgmk2int(x='0')
        x can be str or int, if x is str then it must be a TGMK literal (normalized or not),
        and is converted from TGMK format into int:

            >>> tgmk2int('-3000k1)
            -3072001

        else if x is int then is returned unchanged:

            >>> tgmk2int(-3000 * 1024 - 1)
            -3072001

        If argument is not given then result is 0.

VERSION

    0.4.1

FILE

    /home/xxxx/Documents/pypi/libtgmk/libtgmk/__init__.py


Project details


Download files

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

Source Distribution

libtgmk-0.4.1.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

libtgmk-0.4.1-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page