PHPackages                             ryangriggs/baseconvert - 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. ryangriggs/baseconvert

ActiveLibrary

ryangriggs/baseconvert
======================

A number base conversion utility function supporting arbitrary digit character sets.

20PHP

Since Apr 17Pushed 6y ago1 watchersCompare

[ Source](https://github.com/ryangriggs/baseconvert)[ Packagist](https://packagist.org/packages/ryangriggs/baseconvert)[ RSS](/packages/ryangriggs-baseconvert/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

baseconvert
===========

[](#baseconvert)

PHP arbitrary base conversion function

baseconvert is a fast and simple PHP function that converts numbers from/to arbitrary bases. It can convert from Base-10 to any other base, including binary, octal, hex, or any arbitrary Base-N you can imagine. It can also convert between arbitrary bases. Want to convert from binary to Octal? What about from Hex to a base containing 23 alphanumeric digits? Yep, it works!

It can pad the result with the 0-th digit as needed.

The base character set is customizable, so any characters can be used.

Function parameters:

baseconvert($value, $charset, $pad, $from\_charset)

- $value = the value to convert (in any base, must match the characters listed in $from\_charset)
- $charset = the list of digits to use for the output base. Each digit must be unique, and can be listed as a string with no spaces or array of digits. A base must contain at least 2 characters.
- $pad - left-pad the result to $pad digits, usign the 0-th ordinal of the base $charset. Set to false \[default\] to skip padding, or specify the total length of the result. Results longer than $pad digits will be returned as-is.
- $from\_charset - the character set to use when interpreting $value. By default, this is "0123456789" which is Base-10.

Examples:

// From Base-10 to other bases:

// Convert Base-10 value "100" to Base-2 using the characters 0 and 1. (binary)

baseconvert(100, "01"); // Result: 1100100

// Convert Base-10 value "100" to Base-2 using the characters 0 and 1 (binary) and pad to 8 digits

baseconvert(100, "01", 8); // Result: 01100100

// Convert Base-10 value "100" to Hexadecimal

baseconvert(100, "0123456789abcdef"); // Result: 64

// From other bases to Base-10

// Convert hex value 0xDEADBEEF to decimal

baseconvert("DEADBEEF", "0123456789", false, "0123456789ABCDEF"); // Result: 3735928559

// Convert binary value 10010100101110 to decimal

baseconvert("10010100101110", "0123456789", false, "01"); // Result 9518

// Convert between arbitrary bases:

// Convert Octal 03773 to Hex:

baseconvert("03773", "0123456789abcdef", false, "01234567"); // Result: 7fb

// Convert value "GACT" (Base-4 using the characters "A", "C", "G", "T"), to Base-3 using the characters "X", "Y" and "Z":

baseconvert("GACT", "XYZ", false, "ACGT"); // Result YZXXX

// Convert binary 1011010110101011 to Base-12 using the characters !, @, #, $, %, ^, &amp;, \*, =, :, ?, +

baseconvert("1011010110101011", "!@#$%^&amp;*=:?+", false, "01"); // Result: ##?+*

... I think you get the idea.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/d2fdaed4e00e9eaab46dc5c23295f3b80e5331169386d703203dc5c8fc0f2e9b?d=identicon)[ryangriggs](/maintainers/ryangriggs)

---

Top Contributors

[![ryangriggs](https://avatars.githubusercontent.com/u/5854489?v=4)](https://github.com/ryangriggs "ryangriggs (7 commits)")

### Embed Badge

![Health badge](/badges/ryangriggs-baseconvert/health.svg)

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

PHPackages © 2026

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