Convert numbers between arbitrary notations
This script provides a converter between numbers encoded with n-base notation.
Any notation (using ASCII characters) can be used.
For example, to convert from decimal to hexadecimal notation:
$converter = new NBaseConverter(); echo $converter->convert('12345', 'dec', 'hex'); // => '3039'
You can define your custom notations via the public
$notations property - the
notation names supplied to the
convert method must be defined in
Common notations such as
oct are pre-defined, as well as
base64, plus a URL-safe variation of
_ instead of the standard
/ used by
Also, a useful notation
legible is available, which excludes visually ambiguous
characters such as
O, which can be used to shorten numeric
IDs, e.g. for use in URLs.
Refer to the source code for a list of pre-defined notations.