function Calculator::toArbitraryBase
Converts a non-negative number to an arbitrary base using a custom alphabet.
Parameters
string $number The number to convert, positive or zero, following the Calculator conventions.:
string $alphabet The alphabet that contains every digit, validated as 2 chars minimum.:
int $base The base to convert to, validated from 2 to alphabet length.:
Return value
string The converted number in the given alphabet.
1 call to Calculator::toArbitraryBase()
- Calculator::toBase in vendor/
brick/ math/ src/ Internal/ Calculator.php - Converts a number to an arbitrary base.
File
-
vendor/
brick/ math/ src/ Internal/ Calculator.php, line 409
Class
- Calculator
- Performs basic operations on arbitrary size integers.
Namespace
Brick\Math\InternalCode
public final function toArbitraryBase(string $number, string $alphabet, int $base) : string {
if ($number === '0') {
return $alphabet[0];
}
$base = (string) $base;
$result = '';
while ($number !== '0') {
[
$number,
$remainder,
] = $this->divQR($number, $base);
$remainder = (int) $remainder;
$result .= $alphabet[$remainder];
}
return \strrev($result);
}