{ "info": { "author": "Denis Stepnov", "author_email": "stepnovdenis@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License" ], "description": "## Python Integer Representations & Arithmetic Library\n\nThis tool may be useful to system software developers (for example, compiler or binutils developers). Here are functions for representing integers in a convenient form and functions for arithmetic over integers of arbitrary format.\n\n### Install\n\n $ git clone https://github.com/smurphik/pirep\n $ cd pirep\n $ sudo python3 setup.py install clean\n\nAlternative way:\n\n $ sudo pip3 install pirep\n\n### Formats\n\nThe integer arguments of almost all functions can be of any of 4 formats:\n* **decimal** — usual python integer (`0`, `7`, `-2`, ...);\n* **hexadecimal** — string with or without prefix `'0x'` (`'0xf'`, `'a7'`, and even `'-0xcf'`) or usual hexadecimal int (`0x3`, `0xd`, ..., but python convert it to usual decimal int);\n* **binary** — string with prefix `'0b'` (`'0b010110'`, `'0b0'`, ...) or usual `0b...` integers;\n* **float** — usual python float (Why not? `0.0`, `17.`, `-3.`, ...).\n\nYou can globally specify the default output format for arithmetic functions by call `psetmode()` or locally for each interface (by their parameter `fmt`). Hexadecimal / binary output format is string with prefix `'0x'` / `'0b'`.\n\n### Representations\n\n`c2repr` gives two's complement representation in any output format in accordance with the current signedness and int width (signed 64-bit by default).\n\n >>> from pirep import *\n\n >>> c2repr(5, 'b')\n '0b101'\n\n >>> c2repr(-10)\n '0xfffffffffffffff6'\n\n >>> c2repr('8000000000000000', 'd')\n -9223372036854775808\n\n >>> c2repr('4000000000000000', 'd')\n 4611686018427387904\n\nMeaning of `decomp` by example. The operation `sethi %hi(0x103c00), %o3` (see Sparc Instruction Set) is encoded to `1700040f`. We can clearly expand the code instructions on its fields. For this we need to know the numbers of the last bits of all fields:\n\n >>> decomp('1700040f', (31, 29, 24, 21))\n ['00', '01011', '100', '0000000000010000001111']\n\n >>> decomp('1700040f', (31, 29, 24, 21), 'h')\n ['0x0', '0xb', '0x4', '0x40f']\n\nWhy `'0x40f'` and not `0x103c00`? It's ok. `sethi` sets just 22 high bits:\n\n # Left shift\n >>> psll('0x40f', 10)\n '0x103c00'\n\nWe could just decompose any integer by bytes:\n\n >>> decomp(3932166)\n ['00111100', '00000000', '00000110']\n\nMore verbose way to decode — use `decode()` with object of class `Enc`:\n\n >>> e = Enc('sethi', (('opc', 31), ('rd', 29), ('opc', 24), ('imm22', 21)))\n\n >>> decode('1700040f', e, borders=True)\n opc rd opc imm22\n 00 01011 100 0000000000010000001111\n 31-30 29-25 24-22 21-------------------0\n\n >>> e.field(('opc', 31)).add_only_true(0)\n >>> e.field(('rd', 29)).add_verbose(11, 'eleven')\n\n >>> decode('1700040f', e, 'h')\n opc rd opc imm22\n 0x0 0xb 0x4 0x40f\n\n rd[29:25]: eleven\n\nIt is convenient to have a separate module that contains all the encodings you often use.\n\n### Arithmetic\n\nYou can globally specify the signedness and the integer width by `psetmode()`:\n\n >>> from pirep import *\n\n # Default mode: signed, 64-bit, hexadecimal default output\n >>> pgetmode()\n [True, 64, 'h']\n >>> psub('0x100', 15)\n '0xf1'\n\n # Signed 8-bit int with decimal output by default\n >>> psetmode(True, 8, 'd')\n >>> psub('0x100', 15.)\n -15\n >>> psub('0x100', '0b1111', 'b')\n '0b11110001'\n\n**pirep** contains several other elementary arithmetic functions:\n\n >>> psetmode(True, 8, 'd')\n >>> pmul(3, padd(pdiv('f', '0b100'), prem(11, '0x3')))\n 15\n >>> psetbits(15, (3, 5), '0b110')\n 55\n >>> padd(pintmin(), pintmax())\n -1\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/smurphik/pirep", "keywords": "field bitwise representation arithmetic", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pirep", "package_url": "https://pypi.org/project/pirep/", "platform": "", "project_url": "https://pypi.org/project/pirep/", "project_urls": { "Homepage": "https://github.com/smurphik/pirep" }, "release_url": "https://pypi.org/project/pirep/0.0.2/", "requires_dist": null, "requires_python": "", "summary": "Python Integer Representations & Arithmetic Library", "version": "0.0.2" }, "last_serial": 5366579, "releases": { "0.0.0": [ { "comment_text": "", "digests": { "md5": "4b169d29afa79870c67d8726f70c5f55", "sha256": "8d769eb94e1fd3a4e081fbe0cf0bc22b3410bd08b2de5ea7920bee19bd9db786" }, "downloads": -1, "filename": "pirep-0.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "4b169d29afa79870c67d8726f70c5f55", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8486, "upload_time": "2019-05-12T16:12:15", "url": "https://files.pythonhosted.org/packages/42/9d/7751ace4cafff55a13d6ea87efc9deedd7b7e386469e6423029bf00e41a9/pirep-0.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "43bd96afceca030fc9d8557915b2e3c1", "sha256": "dd552b1377d5ff9d6bbbea59d0ce2e7940237f563af6550bb62d289735e70d5c" }, "downloads": -1, "filename": "pirep-0.0.0.tar.gz", "has_sig": false, "md5_digest": "43bd96afceca030fc9d8557915b2e3c1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7672, "upload_time": "2019-05-12T16:12:17", "url": "https://files.pythonhosted.org/packages/fb/05/c201ea461985a3dbf76dede01b6a244049c2b05faf2c69c4fceff019fd55/pirep-0.0.0.tar.gz" } ], "0.0.1": [ { "comment_text": "", "digests": { "md5": "bc5a9731e4c8017795f9d25d4c0dc746", "sha256": "791469bc6acb5252769ac3e00e9859d827d4a62109481b90148c163dc52f0f35" }, "downloads": -1, "filename": "pirep-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "bc5a9731e4c8017795f9d25d4c0dc746", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8507, "upload_time": "2019-05-12T16:42:14", "url": "https://files.pythonhosted.org/packages/a0/6c/aa7bfc219d1e1dd44c935757c3d08ba999d6857a2393ced1a17d42dde580/pirep-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "69ca3c1a4699fb7dea46cb8f1978db04", "sha256": "b2367ffe464f236711aebfdd833f7e50161976466b4d6816ab0cfd854cc8bd34" }, "downloads": -1, "filename": "pirep-0.0.1.tar.gz", "has_sig": false, "md5_digest": "69ca3c1a4699fb7dea46cb8f1978db04", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7706, "upload_time": "2019-05-12T16:42:15", "url": "https://files.pythonhosted.org/packages/49/72/ba56030178098b1f2f0cacd856072a2c6792b6a43d0083f08fcb6726eef1/pirep-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "8788c38bf63d00caba107fd6645db88b", "sha256": "222867d857b784a9b6320261d672014c46d8a39499b242d535ad634730b7be9a" }, "downloads": -1, "filename": "pirep-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "8788c38bf63d00caba107fd6645db88b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8764, "upload_time": "2019-06-06T10:39:26", "url": "https://files.pythonhosted.org/packages/5b/12/73011c0ba33b5c743fc0baf35cbc6b6c145319e76d19857912b8c36c27c9/pirep-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f11b232ef147e45f483ee803ab37bfef", "sha256": "d0c3e58da9edb1d9e7ded98821d3bba75c2395134122aca412571954827c3068" }, "downloads": -1, "filename": "pirep-0.0.2.tar.gz", "has_sig": false, "md5_digest": "f11b232ef147e45f483ee803ab37bfef", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7940, "upload_time": "2019-06-06T10:39:28", "url": "https://files.pythonhosted.org/packages/40/b5/b838cdbf4478ffb2a611140b8ae38fa1be6462eb1d4c0cddc552d3914dee/pirep-0.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8788c38bf63d00caba107fd6645db88b", "sha256": "222867d857b784a9b6320261d672014c46d8a39499b242d535ad634730b7be9a" }, "downloads": -1, "filename": "pirep-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "8788c38bf63d00caba107fd6645db88b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8764, "upload_time": "2019-06-06T10:39:26", "url": "https://files.pythonhosted.org/packages/5b/12/73011c0ba33b5c743fc0baf35cbc6b6c145319e76d19857912b8c36c27c9/pirep-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f11b232ef147e45f483ee803ab37bfef", "sha256": "d0c3e58da9edb1d9e7ded98821d3bba75c2395134122aca412571954827c3068" }, "downloads": -1, "filename": "pirep-0.0.2.tar.gz", "has_sig": false, "md5_digest": "f11b232ef147e45f483ee803ab37bfef", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7940, "upload_time": "2019-06-06T10:39:28", "url": "https://files.pythonhosted.org/packages/40/b5/b838cdbf4478ffb2a611140b8ae38fa1be6462eb1d4c0cddc552d3914dee/pirep-0.0.2.tar.gz" } ] }