{"id":13828501,"url":"https://github.com/thunderer/Numbase","last_synced_at":"2025-07-09T06:32:07.768Z","repository":{"id":30923709,"uuid":"34481639","full_name":"thunderer/Numbase","owner":"thunderer","description":"Arbitrary number base converter.","archived":false,"fork":false,"pushed_at":"2021-03-02T22:20:15.000Z","size":37,"stargazers_count":24,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-12T21:11:42.569Z","etag":null,"topics":["base","converter","digits","library","math","number"],"latest_commit_sha":null,"homepage":"http://kowalczyk.cc","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"zerbster/ser216","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thunderer.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-04-23T21:07:44.000Z","updated_at":"2024-08-12T19:17:11.000Z","dependencies_parsed_at":"2022-09-10T10:39:40.161Z","dependency_job_id":null,"html_url":"https://github.com/thunderer/Numbase","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thunderer%2FNumbase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thunderer%2FNumbase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thunderer%2FNumbase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thunderer%2FNumbase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thunderer","download_url":"https://codeload.github.com/thunderer/Numbase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225492420,"owners_count":17482869,"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":["base","converter","digits","library","math","number"],"created_at":"2024-08-04T09:02:49.578Z","updated_at":"2024-11-20T08:30:38.611Z","avatar_url":"https://github.com/thunderer.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# Numbase\n\n![Build](https://github.com/thunderer/Numbase/actions/workflows/test.yaml/badge.svg)\n[![License](https://poser.pugx.org/thunderer/numbase/license.svg)](https://packagist.org/packages/thunderer/numbase)\n[![Version](https://poser.pugx.org/thunderer/numbase/v/stable.svg)](https://packagist.org/packages/thunderer/numbase)\n[![Psalm](https://shepherd.dev/github/thunderer/Numbase/coverage.svg)](https://shepherd.dev/github/thunderer/Numbase)\n\nEasily convert numbers between arbitrary bases and symbol sets.\n\n## Installation\n\nThis library is available on [Packagist](https://packagist.org/packages/thunderer/numbase) as `thunderer/numbase`. It requires PHP `\u003e=7.4` and GMP extension for handling large numbers. For older PHP versions please use `^0.1` constraint which works with `5.3` and above.\n\n## Usage\n\n**The Simplest Way\u0026trade;**\n\n```php\nuse Thunder\\Numbase\\Numbase;\n\n$numbase = Numbase::createDefault();\n\n// decimal 15 to hexadecimal number\nassert('F' === $numbase-\u003econvert(15, 10, 16));\n// 64000 decimal to base 32000\nassert('20' === $numbase-\u003econvert(64000, 10, 32000));\n```\n\nRegular usage (see Internals section for more options):\n\n```php\nuse Thunder\\Numbase\\Numbase;\n\n$base62 = new Base62Symbols();\n$numbase = new Numbase(new GmpConverter($base62), new StrictFormatter($base62));\n\n// decimal 15 to hexadecimal number\nassert('F' === $numbase-\u003econvert(15, 10, 16));\n```\n\n**Showcase**\n\nConvert number to and from a different set of symbols:\n\n```php\n$base10 = new Base10Symbols();\n$upper = new StringSymbols('!@#$%^\u0026*()');\n\n$numbase = new Numbase(new GmpDigits($base10), new StrictFormatter($upper));\n\nassert('#!' === $numbase-\u003econvert('20', 10, 10));\nassert('-$!' === $numbase-\u003econvert('-30', 10, 10));\n\n$numbase = new Numbase(new GmpDigits($upper), new StrictFormatter($base10));\n\nassert('20' === $numbase-\u003econvert('#!', 10, 10));\nassert('-30' === $numbase-\u003econvert('-$!', 10, 10));\n```\n\nGet array of digit values (for bases too large for any symbol set):\n\n```php\n$numbase = new Numbase(new GmpDigits(new Base62Symbols()), new ArrayFormatter());\n\n// convert 10^12 to base 99:\nassert(array('10', '61', '53', '3', '51', '60', '10') \n    === $numbase-\u003econvert('10000000000000', 10, 99));\n```\n\n## Internals\n\nNumbase is built upon several concepts:\n\n* **converters** that convert numbers to array of numbers of digits,\n* **formatters** that take those arrays and return final numbers,\n* **symbols** used in converters to check symbols values and to get digits symbols in formatters.\n\nThere are several implementations of each concept bundled with this library, for example:\n\n* converters:\n  * **GmpConverter**: can convert any integer between any base greater than 2, uses `gmp_*()` functions,\n  * **GmpStrvalConverter**: uses `gmp_strval()` to convert between bases 2 and 62,\n  * **BaseConvertConverter**: uses `base_convert()` to convert between bases 2 and 32,\n* formatters:\n  * **ArrayFormatter**: returns raw array of digits numbers,\n  * **StrictFormatter**: returns number as string, throws exception when digit is not found in symbols set,\n  * **FallbackFormatter**: returns number as string, but returns string with digit values separated by configured separator when any digit is not found in symbols set,\n* symbols:\n  * **ArraySymbols**: takes associative `array(value =\u003e symbol)`,\n  * **Base62Symbols**: contains alphanumeric set of symbols `0-9A-Za-z up` to base 62,\n  * **StringSymbols**: takes string and splits it assigning consecutive values to each character.\n\nThe named constructor `Numbase::createDefault()` uses `GmpConverter`, `StrictFormatter` and `Base62Symbols` as defaults.\n\n## License\n\nSee LICENSE file in the main directory of this library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthunderer%2FNumbase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthunderer%2FNumbase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthunderer%2FNumbase/lists"}