PHPackages                             riimu/kit-baseconversion - 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. riimu/kit-baseconversion

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

riimu/kit-baseconversion
========================

Arbitrary precision number base conversion library

v1.2.0(8y ago)35.3k↓46.7%1MITPHPPHP &gt;=5.6.0

Since May 8Pushed 8y ago3 watchersCompare

[ Source](https://github.com/Riimu/Kit-BaseConversion)[ Packagist](https://packagist.org/packages/riimu/kit-baseconversion)[ Docs](http://kit.riimu.net)[ RSS](/packages/riimu-kit-baseconversion/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (3)Versions (8)Used By (1)

Arbitrary Precision Base Converter
==================================

[](#arbitrary-precision-base-converter)

*BaseConversion* is a PHP library for converting number bases, similar to PHP's built in function `base_convert()`. However, unlike the built in function, this library is not limited by 32 bit integers and is capable of converting numbers of arbitrary precision. This library also supports conversion of fractions and allows more customization in terms of number bases.

In order to optimize the conversion of large numbers, this library also employs two different conversion strategies. In some cases, it's possible to convert numbers simply by replacing the digits with digits from the other base (e.g. when converting from base 2 to base 16). This is considerably faster than the other strategy, which simply calculates the new number using arbitrary precision integer arithmetic.

The API documentation, which can be generated using Apigen, can be read online at:

[![Travis](https://camo.githubusercontent.com/4b9465e6c562e03e5b5f85f2e0a6905850962a2b7176172ce777298c38d7fdcf/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f5269696d752f4b69742d42617365436f6e76657273696f6e2e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Riimu/Kit-BaseConversion)[![Scrutinizer](https://camo.githubusercontent.com/343cf13b747d7240d98e6b341527f4b385b5834f8a332b6d5586d1adcd954f8a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f5269696d752f4b69742d42617365436f6e76657273696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Riimu/Kit-BaseConversion/)[![Scrutinizer Coverage](https://camo.githubusercontent.com/fbc1f3d6c5ee2b80c701ce8fa7f13fecb485641da260d7e19e8d632fdc52b819/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f5269696d752f4b69742d42617365436f6e76657273696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Riimu/Kit-BaseConversion/)[![Packagist](https://camo.githubusercontent.com/d7699588352a9e174d5a51b885f64b4fdddeaab999762207793732222b53debe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7269696d752f6b69742d62617365636f6e76657273696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/riimu/kit-baseconversion)

Requirements
------------

[](#requirements)

- The minimum supported PHP version is 5.6
- The library depends on the following PHP Extensions
    - [`gmp`](http://php.net/manual/en/book.gmp.php) (only required IDN support)

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

[](#installation)

### Installation with Composer

[](#installation-with-composer)

The easiest way to install this library is to use Composer to handle your dependencies. In order to install this library via Composer, simply follow these two steps:

1. Acquire the `composer.phar` by running the Composer [Command-line installation](https://getcomposer.org/download/)in your project root.
2. Once you have run the installation script, you should have the `composer.phar`file in you project root and you can run the following command:

    ```
    php composer.phar require "riimu/kit-baseconversion:^1.2"

    ```

After installing this library via Composer, you can load the library by including the `vendor/autoload.php` file that was generated by Composer during the installation.

### Adding the library as a dependency

[](#adding-the-library-as-a-dependency)

If you are already familiar with how to use Composer, you may alternatively add the library as a dependency by adding the following `composer.json` file to your project and running the `composer install` command:

```
{
    "require": {
        "riimu/kit-baseconversion": "^1.2"
    }
}
```

### Manual installation

[](#manual-installation)

If you do not wish to use Composer to load the library, you may also download the library manually by downloading the [latest release](https://github.com/Riimu/Kit-BaseConversion/releases/latest)and extracting the `src` folder to your project. You may then include the provided `src/autoload.php` file to load the library classes.

Usage
-----

[](#usage)

The most convenient way to use this library is via the `baseConvert()` static method provided by the `BaseConverter` class. In most cases, it works the same way as `base_convert()` does. For example:

```
