PHPackages                             ocubom/base-convert - 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. ocubom/base-convert

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

ocubom/base-convert
===================

Safe number conversion between arbitrary bases.

v2.0.3(2y ago)212.0k↓39.5%1MITPHPPHP &gt;=7.0

Since Jan 2Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ocubom/base-convert)[ Packagist](https://packagist.org/packages/ocubom/base-convert)[ Docs](http://github.com/ocubom/base-convert)[ RSS](/packages/ocubom-base-convert/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (7)Used By (1)

Big Numbers Base Convert
========================

[](#big-numbers-base-convert)

Safe number conversion between arbitrary bases.

[![Contributors](https://camo.githubusercontent.com/24b685d1d2b3308be88c7ca6b73da48385a4a479076a17113d19b8a4c67c0707/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f6f6375626f6d2f626173652d636f6e766572742e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ocubom/base-convert/graphs/contributors)[![Forks](https://camo.githubusercontent.com/d6fbc05d248b2a1b08c3fc73e893af1b80b4ee7f63a23d5f15bf511bda776df6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6f6375626f6d2f626173652d636f6e766572742e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ocubom/base-convert/network/members)[![Stargazers](https://camo.githubusercontent.com/0f4c005d32f075b3ed39a766133c9d713780934b93db5a6320830d62d99bc4db/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6f6375626f6d2f626173652d636f6e766572742e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ocubom/base-convert/stargazers)[![Issues](https://camo.githubusercontent.com/f7b2181a4182701ba10e6104b0e931bb86f7b843098cfc104a6a92c85b46d0a3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6f6375626f6d2f626173652d636f6e766572742e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ocubom/base-convert/issues)[![License](https://camo.githubusercontent.com/0f5fa5bf72b599ec87ef301711db7b5e74b209d923f8f544b6d06bb65f956eeb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f6375626f6d2f626173652d636f6e766572742e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ocubom/base-convert/blob/master/LICENSE)[![Version](https://camo.githubusercontent.com/6a918fab2b6ab9769eb0d0b6d89e72aa43609005ff93320a725c36216d2ab0be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6375626f6d2f626173652d636f6e766572742e7376673f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d253233666566656665267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/ocubom/base-convert)[![CI](https://camo.githubusercontent.com/c6cd7f3ed0081855b957e3e5d7cf6313894544bdb562c482f1d6303d0e50d3ee/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f6375626f6d2f626173652d636f6e766572742f63692e796d6c3f6272616e63683d6d61696e266c6162656c3d4349266c6f676f3d676974687562267374796c653d666f722d7468652d6261646765)](https://github.com/ocubom/base-convert/actions/)[![Code Quality](https://camo.githubusercontent.com/b1ed16a82df295f3e39381e199d2da7a0b4d476feb10d78b10b4131eac61e78d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f6f6375626f6d2f626173652d636f6e766572742e7376673f6c6f676f3d7363727574696e697a6572266c6f676f436f6c6f723d666666267374796c653d666f722d7468652d6261646765)](https://scrutinizer-ci.com/g/ocubom/base-convert/)[![Coverage](https://camo.githubusercontent.com/e1f5f893bc369ec09c19668c1b53ed4a1facfd206feb3b3ad4a47de5af2de7d3/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6f6375626f6d2f626173652d636f6e766572742e7376673f6c6f676f3d7363727574696e697a6572266c6f676f436f6c6f723d666666267374796c653d666f722d7468652d6261646765)](https://scrutinizer-ci.com/g/ocubom/base-convert/code-structure/main/code-coverage)

[**Explore the docs »**](https://github.com/ocubom/base-convert)

[Report Bug](https://github.com/ocubom/base-convert/issues)· [Request Feature](https://github.com/ocubom/base-convert/issues)

 Contents- [About](#about-base-convert)
- [Getting Started](#getting-started)
    - [Installation](#installation)
    - [Usage](#usage)
- [Roadmap](#roadmap)
- [Contributing](#contributing)
- [Authorship](#authorship)
- [License](#license)

About Base Convert
------------------

[](#about-base-convert)

[Base Convert](https://github.com/ocubom/base-convert) performs safe number conversion between arbitrary bases. The conversion is performed with a custom implementation to avoid native PHP [base\_convert](https://www.php.net/manual/function.base-convert.php "PHP base_convert") function [float precision problem](http://php.net/manual/language.types.float.php "PHP Floating point numbers").

The implementation used is extracted from the [Symfony UID component](https://symfony.com/doc/current/components/uid.html). The class `BinaryUtil` implements the necessary `fromBase` and `toBase` methods. These methods have been extracted to ensure compatibility (it is an internal class) and to reduce the minimum PHP version requirement.

Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

Make sure [Composer](http://getcomposer.org/) is installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md) of the Composer documentation.

```
$ composer require ocubom/base-convert
```

### Usage

[](#usage)

Just use like the native [base\_convert](https://www.php.net/manual/function.base-convert.php "PHP base_convert"). Although the implementation is compatible with native conversion it provides some improvements:

- Bases can be between 2 and 62. The native version only supports bases between 2 and 36.

    The conversion uses [Base62](https://wikipedia.org/wiki/Base62) in the same manner as the [GMP extension](https://www.php.net/manual/book.gmp.php "PHP GMP extension"). The conversions are compatible.
- "Named bases" are supported.

    NameBase`dec`base-10`hex`base-16`oct`base-8
- The special base `bin` can be used to convert from/to binary strings. This can be used to directly convert binary outputs of some functions.

    ```
    use function \Ocubom\Math\base_convert;

    $hex = base_convert(random_bytes(32), 'bin', 'hex');
    ```

    > **Warning**
    >
    > Do not confuse a binary encoding (`bin`) with the Base2 encoding (a text string with the characters `0` and `1`).
    >
    > In PHP there are several functions:
    >
    >
    > - [bin2hex](https://www.php.net/manual/function.bin2hex.php "PHP bin2hex")/[hex2bin](https://www.php.net/manual/function.hex2bin.php "PHP hex2bin") that convert between hexadecimal and binary.
    > - [bindec](https://www.php.net/manual/function.bindec.php "PHP bindec")/[decbin](https://www.php.net/manual/function.decbin.php "PHP decbin") that convert between Base2 and Base10.
    >
    > In this library the string `bin` has been considered to be equivalent to the first set of functions.
- New bases can be used by implementing the base interface.

    Includes bases for Douglas Crockford Base32 and Satoshi Nakamoto Base58 encodings. The implementations are examples of how to customize your own encoding.

#### [Douglas Crockford Base 32 encoding](https://www.crockford.com/base32.html)

[](#douglas-crockford-base32-encoding)

A secure version of the Base 32 encoding proposed by Douglas Crockford.

> **Note**
>
> The encoding scheme is required to
>
> - Be human-readable and machine-readable.
> - Be compact. Humans have difficulty in manipulating long strings of arbitrary symbols.
> - Be error resistant. Entering the symbols must not require keyboarding gymnastics.
> - Be pronounceable. Humans should be able to accurately transmit the symbols to other humans using a telephone.
>
> \-- Douglas Crockford. [Base 32](https://www.crockford.com/base32.html)

This encoding is accessible:

- By passing a `Crockford` object as any of the base arguments of the `base_convert` function.

    ```
    use Ocubom\Math\Base\Crockford;
    use function Ocubom\Math\base_convert;

    // Encoding
    $crockford = base_convert(random_bytes(32), 'bin', new Crockford());

    // Decoding
    $hex = base_convert($crockford, new Crockford(), 'hex');
    ```
- Using the `encode` and `decode` methods of the `Crockford` class.

    ```
    use Ocubom\Math\Crockford;

    // Encoding
    $crockford = Crockford::encode(random_bytes(32), 'bin');

    // Decoding
    $hex = Crockford::decode($crockford, 'hex');
    ```
- Using the `crockford_encode` and `crockford_decode` functions.

    ```
    use function \Ocubom\Math\crockford_decode;
    use function \Ocubom\Math\crockford_encode;

    // Encoding
    $crockford = crockford_encode(random_bytes(32), 'bin');

    // Decoding
    $hex = crockford_decode($crockford, 'hex');
    ```

An additional parameter can be added to include a checksum for error detection.

#### Satoshi Nakamoto Base 58 encoding

[](#satoshi-nakamoto-base58-encoding)

Bitcoin addresses use a variant of Base 64 that omits characters that can lead to confusion. The result is a Base 58 encoding.

> **Note**
>
> Why base-58 instead of standard base-64 encoding?
>
> - Don't want 0OIl characters that look the same in some fonts and could be used to create visually identical looking data.
> - A string with non-alphanumeric characters is not as easily accepted as input.
> - E-mail usually won't line-break if there's no punctuation to break at.
> - Double-clicking selects the whole string as one word if it's all alphanumeric.
>
> \-- Satoshi Nakamoto. [Bitcoin source code](https://github.com/bitcoin/bitcoin/blob/v23.0/src/base58.h#L7-L12)

This encoding is accessible by passing a `Base58` object as any of the base arguments of the `base_convert` function.

```
use Ocubom\Math\Base\Base58;
use function Ocubom\Math\base_convert;

// Encoding
$base58 = base_convert(random_bytes(32), 'bin', new Base58());

// Decoding
$hex = base_convert($base58, new Base58(), 'hex');
```

Roadmap
-------

[](#roadmap)

See the [open issues](https://github.com/ocubom/base-convert/issues) for a full list of proposed features (and known issues).

Contributing
------------

[](#contributing)

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".

1. Fork the Project.
2. Create your Feature Branch (`git checkout -b feature/your-feature`).
3. Commit your Changes (`git commit -m 'Add your-feature'`).
4. Push to the Branch (`git push origin feature/your-feature`).
5. Open a Pull Request.

Authorship
----------

[](#authorship)

- Oscar Cubo Medina —

See also the list of [contributors](https://github.com/ocubom/base-convert/graphs/contributors) who participated in this project.

License
-------

[](#license)

Distributed under the MIT License. See [LICENSE](https://github.com/ocubom/base-convert/blob/master/LICENSE) for more information.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~505 days

Recently: every ~632 days

Total

6

Last Release

894d ago

Major Versions

v1.0.0 → v2.0.02022-08-29

PHP version history (2 changes)1.0.x-devPHP &gt;=5.4

v2.0.0PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/642ac779b1c36bfa6dfae27c756efcf88f75ff34fd50b376a72acb05e845502d?d=identicon)[ocubom](/maintainers/ocubom)

---

Top Contributors

[![ocubom](https://avatars.githubusercontent.com/u/184187?v=4)](https://github.com/ocubom "ocubom (19 commits)")

---

Tags

arbitrary-precisionbasebase-converterbase62big-numbersbinarycrockfordcrockford-base32hexadecimalnumberphpArbitrary-precisionbase32binarybasenumberprecisionhexadecimalcrockfordbigbig number

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/ocubom-base-convert/health.svg)

```
[![Health](https://phpackages.com/badges/ocubom-base-convert/health.svg)](https://phpackages.com/packages/ocubom-base-convert)
```

###  Alternatives

[brick/math

Arbitrary-precision arithmetic library

2.1k504.0M277](/packages/brick-math)[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)[christian-riesen/base32

Base32 encoder/decoder according to RFC 4648

13331.8M61](/packages/christian-riesen-base32)[php-decimal/php-decimal

Correctly-rounded arbitrary precision decimal floating point

781.0M9](/packages/php-decimal-php-decimal)[ionux/phactor

Phactor is a high-performance PHP implementation of the elliptic curve math functions required to generate &amp; verify private/public (asymmetric) EC keypairs and ECDSA signatures based on secp256k1 curve parameters. This library also includes a class to generate Service Identification Numbers (SINs) based on the published Identity Protocol v1 spec.

5275.0k30](/packages/ionux-phactor)[ademarre/binary-to-text-php

Collection of binary-to-text encoding utilities for PHP. Includes Base32 support and much more.

40165.8k](/packages/ademarre-binary-to-text-php)

PHPackages © 2026

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