{"id":22999042,"url":"https://github.com/ocubom/base-convert","last_synced_at":"2025-10-26T21:02:56.158Z","repository":{"id":25653979,"uuid":"29089419","full_name":"ocubom/base-convert","owner":"ocubom","description":"Safe number conversion between arbitrary bases.","archived":false,"fork":false,"pushed_at":"2023-12-06T11:20:41.000Z","size":66,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-18T09:52:17.738Z","etag":null,"topics":["arbitrary-precision","base","base-converter","base62","big-numbers","binary","crockford","crockford-base32","hexadecimal","number","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/ocubom.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}},"created_at":"2015-01-11T11:26:19.000Z","updated_at":"2024-09-18T19:54:00.000Z","dependencies_parsed_at":"2023-01-14T03:03:34.864Z","dependency_job_id":null,"html_url":"https://github.com/ocubom/base-convert","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocubom%2Fbase-convert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocubom%2Fbase-convert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocubom%2Fbase-convert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocubom%2Fbase-convert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ocubom","download_url":"https://codeload.github.com/ocubom/base-convert/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229786968,"owners_count":18124014,"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":["arbitrary-precision","base","base-converter","base62","big-numbers","binary","crockford","crockford-base32","hexadecimal","number","php"],"created_at":"2024-12-15T06:15:22.271Z","updated_at":"2025-10-26T21:02:51.119Z","avatar_url":"https://github.com/ocubom.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\nBig Numbers Base Convert\n========================\n\nSafe number conversion between arbitrary bases.\n\n[![Contributors][contributors-img]][contributors-url]\n[![Forks][forks-img]][forks-url]\n[![Stargazers][stars-img]][stars-url]\n[![Issues][issues-img]][issues-url]\n[![License][license-img]][license-url]\n[![Version][packagist-img]][packagist-url]\n[![CI][workflow-ci-img]][workflow-ci-url]\n[![Code Quality][quality-img]][quality-url]\n[![Coverage][coverage-img]][coverage-url]\n\n[**Explore the docs »**](https://github.com/ocubom/base-convert)\n\n[Report Bug](https://github.com/ocubom/base-convert/issues)\n·\n[Request Feature](https://github.com/ocubom/base-convert/issues)\n\n\u003c/div\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eContents\u003c/summary\u003e\n\n* [About](#about-base-convert)\n* [Getting Started](#getting-started)\n    * [Installation](#installation)\n    * [Usage](#usage)\n* [Roadmap](#roadmap)\n* [Contributing](#contributing)\n* [Authorship](#authorship)\n* [License](#license)\n\n\u003c/details\u003e\n\n## About Base Convert\n\n[Base Convert](https://github.com/ocubom/base-convert) performs safe number conversion between arbitrary bases.\nThe conversion is performed with a custom implementation to avoid native PHP [base_convert][] function [float precision problem][].\n\nThe implementation used is extracted from the [Symfony UID component][].\nThe class `BinaryUtil` implements the necessary `fromBase` and `toBase` methods.\nThese methods have been extracted to ensure compatibility (it is an internal class) and to reduce the minimum PHP version requirement.\n\n## Getting Started\n\n### Installation\n\nMake sure [Composer][] is installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md) of the Composer documentation.\n\n```console\n$ composer require ocubom/base-convert\n```\n\n### Usage\n\nJust use like the native [base_convert][].\nAlthough the implementation is compatible with native conversion it provides some improvements:\n\n* Bases can be between 2 and 62.\n  The native version only supports bases between 2 and 36.\n\n  The conversion uses [Base62][] in the same manner as the [GMP extension][].\n  The conversions are compatible.\n\n* \"Named bases\" are supported. \n\n  | Name  |  Base   |\n  |:-------:|:-------:|\n  | `dec` | base-10 |\n  | `hex` | base-16 |\n  | `oct` | base-8  |\n\n* The special base `bin` can be used to convert from/to binary strings.\n  This can be used to directly convert binary outputs of some functions.\n\n  ```php\n  use function \\Ocubom\\Math\\base_convert;\n  \n  $hex = base_convert(random_bytes(32), 'bin', 'hex');\n  ```\n  \n  \u003e **Warning**\n  \u003e\n  \u003e Do not confuse a binary encoding (`bin`) with the Base2 encoding (a text string with the characters `0` and `1`).\n  \u003e \n  \u003e In PHP there are several functions:\n  \u003e \n  \u003e * [bin2hex][]/[hex2bin][] that convert between hexadecimal and binary.\n  \u003e \n  \u003e * [bindec][]/[decbin][] that convert between Base2 and Base10.\n  \u003e \n  \u003e In this library the string `bin` has been considered to be equivalent to the first set of functions.\n\n\n* New bases can be used by implementing the base interface.\n\n  Includes bases for Douglas Crockford Base32 and Satoshi Nakamoto Base58 encodings.\n  The implementations are examples of how to customize your own encoding.\n\n#### [Douglas Crockford Base 32 encoding](https://www.crockford.com/base32.html)\n\nA secure version of the Base 32 encoding proposed by Douglas Crockford.\n\n\u003e **Note**\n\u003e\n\u003e The encoding scheme is required to\n\u003e\n\u003e * Be human-readable and machine-readable.\n\u003e\n\u003e * Be compact.\n\u003e   Humans have difficulty in manipulating long strings of arbitrary symbols.\n\u003e\n\u003e * Be error resistant.\n\u003e   Entering the symbols must not require keyboarding gymnastics.\n\u003e\n\u003e * Be pronounceable.\n\u003e   Humans should be able to accurately transmit the symbols to other humans using a telephone.\n\u003e\n\u003e -- Douglas Crockford. [Base 32](https://www.crockford.com/base32.html)\n\nThis encoding is accessible:\n\n* By passing a `Crockford` object as any of the base arguments of the `base_convert` function.\n\n  ```php\n  use Ocubom\\Math\\Base\\Crockford;\n  use function Ocubom\\Math\\base_convert;\n  \n  // Encoding\n  $crockford = base_convert(random_bytes(32), 'bin', new Crockford());\n\n  // Decoding\n  $hex = base_convert($crockford, new Crockford(), 'hex');\n  ```\n\n* Using the `encode` and `decode` methods of the `Crockford` class.\n\n  ```php\n  use Ocubom\\Math\\Crockford;\n  \n  // Encoding\n  $crockford = Crockford::encode(random_bytes(32), 'bin');\n\n  // Decoding\n  $hex = Crockford::decode($crockford, 'hex');\n  ```\n\n* Using the `crockford_encode` and `crockford_decode` functions.\n\n  ```php\n  use function \\Ocubom\\Math\\crockford_decode;\n  use function \\Ocubom\\Math\\crockford_encode;\n  \n  // Encoding\n  $crockford = crockford_encode(random_bytes(32), 'bin');\n\n  // Decoding\n  $hex = crockford_decode($crockford, 'hex');\n  ```\n\nAn additional parameter can be added to include a checksum for error detection.\n\n#### Satoshi Nakamoto Base 58 encoding\n\nBitcoin addresses use a variant of Base 64 that omits characters that can lead to confusion.\nThe result is a Base 58 encoding.\n\n\u003e **Note**\n\u003e \n\u003e Why base-58 instead of standard base-64 encoding?\n\u003e \n\u003e * Don't want 0OIl characters that look the same in some fonts and could be used to create visually identical looking data.\n\u003e\n\u003e * A string with non-alphanumeric characters is not as easily accepted as input.\n\u003e\n\u003e * E-mail usually won't line-break if there's no punctuation to break at.\n\u003e\n\u003e * Double-clicking selects the whole string as one word if it's all alphanumeric.\n\u003e\n\u003e -- Satoshi Nakamoto. [Bitcoin source code](https://github.com/bitcoin/bitcoin/blob/v23.0/src/base58.h#L7-L12)\n\nThis encoding is accessible by passing a `Base58` object as any of the base arguments of the `base_convert` function.\n\n  ```php\n  use Ocubom\\Math\\Base\\Base58;\n  use function Ocubom\\Math\\base_convert;\n  \n  // Encoding\n  $base58 = base_convert(random_bytes(32), 'bin', new Base58());\n\n  // Decoding\n  $hex = base_convert($base58, new Base58(), 'hex');\n  ```\n\n## Roadmap\n\nSee the [open issues](https://github.com/ocubom/base-convert/issues) for a full list of proposed features (and known issues).\n\n## Contributing\n\nContributions are what make the open source community such an amazing place to learn, inspire, and create.\nAny contributions you make are **greatly appreciated**.\n\nIf you have a suggestion that would make this better, please fork the repo and create a pull request.\nYou can also simply open an issue with the tag \"enhancement\".\n\n1. Fork the Project.\n2. Create your Feature Branch (`git checkout -b feature/your-feature`).\n3. Commit your Changes (`git commit -m 'Add your-feature'`).\n4. Push to the Branch (`git push origin feature/your-feature`).\n5. Open a Pull Request.\n\n## Authorship\n\n* Oscar Cubo Medina — https://ocubom.github.io\n\nSee also the list of [contributors][contributors-url] who participated in this project.\n\n## License\n\nDistributed under the MIT License.\nSee [LICENSE][] for more information.\n\n\n[LICENSE]: https://github.com/ocubom/base-convert/blob/master/LICENSE\n\n\n\u003c!-- Links --\u003e\n\n[Base62]: https://wikipedia.org/wiki/Base62\n\n[base_convert]: https://www.php.net/manual/function.base-convert.php\n    \"PHP base_convert\"\n\n[Composer]: http://getcomposer.org/\n\n[Crockford Base32]: http://www.crockford.com/wrmg/base32.html\n    \"Douglas Crockford's Base32 Encoding\"\n\n[float precision problem]: http://php.net/manual/language.types.float.php\n    \"PHP Floating point numbers\"\n\n[GMP extension]: https://www.php.net/manual/book.gmp.php\n    \"PHP GMP extension\"\n\n[bin2hex]: https://www.php.net/manual/function.bin2hex.php\n    \"PHP bin2hex\"\n\n[hex2bin]: https://www.php.net/manual/function.hex2bin.php\n    \"PHP hex2bin\"\n\n[bindec]: https://www.php.net/manual/function.bindec.php\n    \"PHP bindec\"\n\n[decbin]: https://www.php.net/manual/function.decbin.php\n    \"PHP decbin\"\n\n[Symfony UID component]: https://symfony.com/doc/current/components/uid.html\n\n\u003c!-- Project Badges --\u003e\n[contributors-img]: https://img.shields.io/github/contributors/ocubom/base-convert.svg?style=for-the-badge\n[contributors-url]: https://github.com/ocubom/base-convert/graphs/contributors\n[forks-img]:        https://img.shields.io/github/forks/ocubom/base-convert.svg?style=for-the-badge\n[forks-url]:        https://github.com/ocubom/base-convert/network/members\n[stars-img]:        https://img.shields.io/github/stars/ocubom/base-convert.svg?style=for-the-badge\n[stars-url]:        https://github.com/ocubom/base-convert/stargazers\n[issues-img]:       https://img.shields.io/github/issues/ocubom/base-convert.svg?style=for-the-badge\n[issues-url]:       https://github.com/ocubom/base-convert/issues\n[license-img]:      https://img.shields.io/github/license/ocubom/base-convert.svg?style=for-the-badge\n[license-url]:      https://github.com/ocubom/base-convert/blob/master/LICENSE\n[workflow-ci-img]:  https://img.shields.io/github/actions/workflow/status/ocubom/base-convert/ci.yml?branch=main\u0026label=CI\u0026logo=github\u0026style=for-the-badge\n[workflow-ci-url]:  https://github.com/ocubom/base-convert/actions/\n[packagist-img]:    https://img.shields.io/packagist/v/ocubom/base-convert.svg?logo=packagist\u0026logoColor=%23fefefe\u0026style=for-the-badge\n[packagist-url]:    https://packagist.org/packages/ocubom/base-convert\n[coverage-img]:     https://img.shields.io/scrutinizer/coverage/g/ocubom/base-convert.svg?logo=scrutinizer\u0026logoColor=fff\u0026style=for-the-badge\n[coverage-url]:     https://scrutinizer-ci.com/g/ocubom/base-convert/code-structure/main/code-coverage\n[quality-img]:      https://img.shields.io/scrutinizer/quality/g/ocubom/base-convert.svg?logo=scrutinizer\u0026logoColor=fff\u0026style=for-the-badge\n[quality-url]:      https://scrutinizer-ci.com/g/ocubom/base-convert/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focubom%2Fbase-convert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Focubom%2Fbase-convert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focubom%2Fbase-convert/lists"}