Download the PHP package thunderer/numbase without Composer
On this page you can find all versions of the php package thunderer/numbase. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package numbase
Numbase
Easily convert numbers between arbitrary bases and symbol sets.
Installation
This library is available on Packagist as thunderer/numbase
. It requires PHP >=7.4
and GMP extension for handling large numbers. For older PHP versions please use ^0.1
constraint which works with 5.3
and above.
Usage
The Simplest Way™
Regular usage (see Internals section for more options):
Showcase
Convert number to and from a different set of symbols:
Get array of digit values (for bases too large for any symbol set):
Internals
Numbase is built upon several concepts:
- converters that convert numbers to array of numbers of digits,
- formatters that take those arrays and return final numbers,
- symbols used in converters to check symbols values and to get digits symbols in formatters.
There are several implementations of each concept bundled with this library, for example:
- converters:
- GmpConverter: can convert any integer between any base greater than 2, uses
gmp_*()
functions, - GmpStrvalConverter: uses
gmp_strval()
to convert between bases 2 and 62, - BaseConvertConverter: uses
base_convert()
to convert between bases 2 and 32,
- GmpConverter: can convert any integer between any base greater than 2, uses
- formatters:
- ArrayFormatter: returns raw array of digits numbers,
- StrictFormatter: returns number as string, throws exception when digit is not found in symbols set,
- FallbackFormatter: returns number as string, but returns string with digit values separated by configured separator when any digit is not found in symbols set,
- symbols:
- ArraySymbols: takes associative
array(value => symbol)
, - Base62Symbols: contains alphanumeric set of symbols
0-9A-Za-z up
to base 62, - StringSymbols: takes string and splits it assigning consecutive values to each character.
- ArraySymbols: takes associative
The named constructor Numbase::createDefault()
uses GmpConverter
, StrictFormatter
and Base62Symbols
as defaults.
License
See LICENSE file in the main directory of this library.
All versions of numbase with dependencies
ext-gmp Version *