PHPackages                             thunderer/numbase - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. thunderer/numbase

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

thunderer/numbase
=================

Convert any number between arbitrary bases

v0.1.2(9y ago)242.3k3MITPHPPHP ^5.3|^7.0

Since Apr 27Pushed 5y ago2 watchersCompare

[ Source](https://github.com/thunderer/Numbase)[ Packagist](https://packagist.org/packages/thunderer/numbase)[ RSS](/packages/thunderer-numbase/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Numbase
=======

[](#numbase)

[![Build](https://github.com/thunderer/Numbase/actions/workflows/test.yaml/badge.svg)](https://github.com/thunderer/Numbase/actions/workflows/test.yaml/badge.svg)[![License](https://camo.githubusercontent.com/33382b99567cfa415d77c5c7c8d40b3f0e77b743c6b548b60b3c589ccbdaad10/68747470733a2f2f706f7365722e707567782e6f72672f7468756e64657265722f6e756d626173652f6c6963656e73652e737667)](https://packagist.org/packages/thunderer/numbase)[![Version](https://camo.githubusercontent.com/50d523c9b949fe0181d19d033e68fcd21d9c53daae20d6f28808f2ab09ec243a/68747470733a2f2f706f7365722e707567782e6f72672f7468756e64657265722f6e756d626173652f762f737461626c652e737667)](https://packagist.org/packages/thunderer/numbase)[![Psalm](https://camo.githubusercontent.com/76b8715c33436d8c1104a0b2aad05b6df1c32df119303719adf35bcb412e7f95/68747470733a2f2f73686570686572642e6465762f6769746875622f7468756e64657265722f4e756d626173652f636f7665726167652e737667)](https://shepherd.dev/github/thunderer/Numbase)

Easily convert numbers between arbitrary bases and symbol sets.

Installation
------------

[](#installation)

This library is available on [Packagist](https://packagist.org/packages/thunderer/numbase) as `thunderer/numbase`. It requires PHP `>=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.

Usage
-----

[](#usage)

**The Simplest Way™**

```
use Thunder\Numbase\Numbase;

$numbase = Numbase::createDefault();

// decimal 15 to hexadecimal number
assert('F' === $numbase->convert(15, 10, 16));
// 64000 decimal to base 32000
assert('20' === $numbase->convert(64000, 10, 32000));
```

Regular usage (see Internals section for more options):

```
use Thunder\Numbase\Numbase;

$base62 = new Base62Symbols();
$numbase = new Numbase(new GmpConverter($base62), new StrictFormatter($base62));

// decimal 15 to hexadecimal number
assert('F' === $numbase->convert(15, 10, 16));
```

**Showcase**

Convert number to and from a different set of symbols:

```
$base10 = new Base10Symbols();
$upper = new StringSymbols('!@#$%^&*()');

$numbase = new Numbase(new GmpDigits($base10), new StrictFormatter($upper));

assert('#!' === $numbase->convert('20', 10, 10));
assert('-$!' === $numbase->convert('-30', 10, 10));

$numbase = new Numbase(new GmpDigits($upper), new StrictFormatter($base10));

assert('20' === $numbase->convert('#!', 10, 10));
assert('-30' === $numbase->convert('-$!', 10, 10));
```

Get array of digit values (for bases too large for any symbol set):

```
$numbase = new Numbase(new GmpDigits(new Base62Symbols()), new ArrayFormatter());

// convert 10^12 to base 99:
assert(array('10', '61', '53', '3', '51', '60', '10')
    === $numbase->convert('10000000000000', 10, 99));
```

Internals
---------

[](#internals)

Numbase is built upon several concepts:

- **converters** that convert numbers to array of numbers of digits,
- **formatters** that take those arrays and return final numbers,
- **symbols** used in converters to check symbols values and to get digits symbols in formatters.

There are several implementations of each concept bundled with this library, for example:

- converters:
    - **GmpConverter**: can convert any integer between any base greater than 2, uses `gmp_*()` functions,
    - **GmpStrvalConverter**: uses `gmp_strval()` to convert between bases 2 and 62,
    - **BaseConvertConverter**: uses `base_convert()` to convert between bases 2 and 32,
- formatters:
    - **ArrayFormatter**: returns raw array of digits numbers,
    - **StrictFormatter**: returns number as string, throws exception when digit is not found in symbols set,
    - **FallbackFormatter**: returns number as string, but returns string with digit values separated by configured separator when any digit is not found in symbols set,
- symbols:
    - **ArraySymbols**: takes associative `array(value => symbol)`,
    - **Base62Symbols**: contains alphanumeric set of symbols `0-9A-Za-z up` to base 62,
    - **StringSymbols**: takes string and splits it assigning consecutive values to each character.

The named constructor `Numbase::createDefault()` uses `GmpConverter`, `StrictFormatter` and `Base62Symbols` as defaults.

License
-------

[](#license)

See LICENSE file in the main directory of this library.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~314 days

Total

3

Last Release

3411d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.3

v0.1.1PHP ^5.3|^7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1087180?v=4)[Tomasz Kowalczyk](/maintainers/Thunderer)[@thunderer](https://github.com/thunderer)

---

Top Contributors

[![thunderer](https://avatars.githubusercontent.com/u/1087180?v=4)](https://github.com/thunderer "thunderer (19 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

baseconverterdigitslibrarymathnumberconverterbasenumber

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thunderer-numbase/health.svg)

```
[![Health](https://phpackages.com/badges/thunderer-numbase/health.svg)](https://phpackages.com/packages/thunderer-numbase)
```

###  Alternatives

[matthiasmullie/path-converter

Relative path converter

10229.6M7](/packages/matthiasmullie-path-converter)[hnhdigital-os/laravel-number-converter

Number to word, roman, ordinal converter

20163.3k2](/packages/hnhdigital-os-laravel-number-converter)[aza/math

AzaMath - Anizoptera CMF mathematic component. Arbitrary precision arithmetic (for huge integers; BCMath wrapper) and universal convertor between positional numeral systems (supported bases from 2 to 62 inclusive, and systems with custom alphabet; pure PHP realisation, can use GMP and core PHP functions for speed optimization).

1921.9k1](/packages/aza-math)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
