cartware/custombase

A PHP port of Elixir's CustomBase module

1.0.0 2022-04-01 08:21 UTC

This package is auto-updated.

Last update: 2024-10-29 06:06:03 UTC


README

A PHP port of Elixir's CustomBase module

Example

Lets make Base12 module with conversion described below.

use Cartware\CustomBase\CustomBase;

class Base12 {
	use CustomBase;
	protected const CUSTOMBASE_ALPHABET = '0123456789AB';
}

Now your class has 2 functions encode/1 and decode/1:

$base12 = new Base12();

$base12->encode(9); # 9
$base12->encode(10); # A
$base12->encode(11); # B
$base12->encode(12); # 10

$base12->decode(16); # 18
$base12->decode('AB'); # 131

License

Released under the MIT License.