{"id":21954078,"url":"https://github.com/goessl/rdx","last_synced_at":"2025-03-22T18:27:39.698Z","repository":{"id":189828013,"uuid":"681402093","full_name":"goessl/rdx","owner":"goessl","description":"Radix conversion module.","archived":false,"fork":false,"pushed_at":"2023-09-06T18:16:54.000Z","size":211,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T10:56:53.397Z","etag":null,"topics":["binary","hexadecimal","infinite","lightweight","number","number-system-conversion","number-system-converter","number-systems","number-theory","numbers","octal","pip","pip3","python","python3","radix","unlimited"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goessl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-22T00:10:35.000Z","updated_at":"2023-10-28T10:18:04.000Z","dependencies_parsed_at":"2025-01-27T22:45:51.414Z","dependency_job_id":"f66631d2-7e97-4903-8c80-24ed2b8baad2","html_url":"https://github.com/goessl/rdx","commit_stats":null,"previous_names":["goessl/rdx"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goessl%2Frdx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goessl%2Frdx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goessl%2Frdx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goessl%2Frdx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goessl","download_url":"https://codeload.github.com/goessl/rdx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245001781,"owners_count":20545313,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary","hexadecimal","infinite","lightweight","number","number-system-conversion","number-system-converter","number-systems","number-theory","numbers","octal","pip","pip3","python","python3","radix","unlimited"],"created_at":"2024-11-29T07:15:26.065Z","updated_at":"2025-03-22T18:27:39.669Z","avatar_url":"https://github.com/goessl.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rdx\n\nA radix conversion module.\n\nImplementation of\n- [How to convert an integer to a string in any base?](https://stackoverflow.com/questions/2267362/how-to-convert-an-integer-to-a-string-in-any-base)\n- [How to find length of digits in an integer?](https://stackoverflow.com/questions/2189800/how-to-find-length-of-digits-in-an-integer)\n\n## Installation\n\n```\npip install rdx\n```\n\n## Usage\n\nThis module provides the following functions:\n- `int_to_digits(n, b=10)`:\nReturns the digits of number `n` in base `b`.\n- `digits_to_int(d, b=10)`:\nReturns the number represented by the digits `d`\nin base `b`.\n  ```python\n  \u003e\u003e\u003e from rdx import *\n  \u003e\u003e\u003e int_to_digits(42, 2)\n  [0, 1, 0, 1, 0, 1]\n  \u003e\u003e\u003e int_to_digits(42, 16)\n  [10, 2]\n  \u003e\u003e\u003e digits_to_int([27, 1], 42)\n  69\n  ```\n- `int_to_len_digits(n, b=10)`:\nReturns the amount of digits the number `n` represented in base `b` needs.\n   ```python\n   \u003e\u003e\u003e int_to_len_digits(1024, 2)\n   11\n   ```\n- `digits_to_characters(d, alphabet=digits+ascii_letters)`:\nConverts integer digits `d` to characters of the given alphabet.\n- `characters_to_digits(s, alphabet=digits+ascii_letters)`:\nConverts characters `s` of the given alphabet to integer digits.\n  ```python\n  \u003e\u003e\u003e digits_to_characters([0, 1, 9, 10, 15, 16])\n  ['0', '1', '9', 'a', 'f', 'g']\n  \u003e\u003e\u003e characters_to_digits(['0', '1', '9', 'a', 'f', 'g'])\n  [0, 1, 9, 10, 15, 16]\n  ```\n- `digits_to_string(d, alphabet=string.digits+string.ascii_letters)`:\nConverts integer digits `d` to a right-to-left string in the given alphabet.\n- `string_to_digits(s, alphabet=string.digits+string.ascii_letters)`:\nConverts a right-to-left string `s` in the given alphabet to integer digits.\n  ```python\n  \u003e\u003e\u003e digits_to_string([0, 0, 15])\n  'f00'\n  \u003e\u003e\u003e string_to_digits('f12')\n  [2, 1, 15]\n  ```\n\n## Conventions\n\n### Data type\n\nCurrently digits or characters are returned as lists.\nIn the future this will be switched to tuples\nas they are more similar to strings,\nand a digit representation is similar to a string.\n\nDigit or character arguments should be provided in form of an iterable,\nnot an iterator, as in most functions the will be iterated twice\nand an iterator will be exhausted after the first run.\n\n### Ordering\n\nAs a digit representation a list of integers is used,\nwhere every element represents a digit, all ordered in ascending positions.\nSo the lowest digit at position with index 0, will be at position 0.\nBut this also means, that when a list of digits is printed,\nit will be ordered left-to-right,\nopposed to the usual human-readable right-to-left.\nE.g. `12` (twelve) corresponds to `[2, 1]`.\n\n### `int_to_len_digits(n)` vs `len(int_to_digits(n))`\n\n`len(int_to_digits(n))` is the naive and non-optimal approach.\n`int_to_len_digits(n)` calculates the number of digits intelligently as\n`int(log(n, b))+1` as mentioned\nin the [discussion](https://stackoverflow.com/a/2189827/7367030).\nBut to avoid errors due to [`math.log`](https://docs.python.org/3/library/math.html#math.log)\nusing floating point arithmetic\n[`sympy.log`](https://docs.sympy.org/latest/modules/functions/elementary.html#sympy.functions.elementary.exponential.log)\nis used, adding a hefty overhead. A comparison for time critical applications:\n![png](https://raw.githubusercontent.com/goessl/rdx/main/readme_nudes/int_to_len_digits_runtime.png)\n(integers with just 3s were choosen because random values introduce to much\nnoise and because 100... seemed to risky for a systematic error and 33... lies\nexactly between those 100...s on a logarithmic scale)\n\n## TODO\n\n- [ ] put digits in tuples instead of lists\n- [ ] non-standard positional numeral systems\n  - [ ] [mixed radix](https://en.wikipedia.org/wiki/Mixed_radix)\n    - [ ] [factorial](https://en.wikipedia.org/wiki/Factorial_number_system)\n    - [ ] primorial\n    - [ ] ...\n  - [ ] [negative base](https://en.wikipedia.org/wiki/Negative_base)\n  - [ ] [complex base](https://en.wikipedia.org/wiki/Quater-imaginary_base)\n\n## License (MIT)\n\nCopyright (c) 2023 Sebastian Gössl\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoessl%2Frdx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoessl%2Frdx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoessl%2Frdx/lists"}