function BigInteger::toArbitraryBase
Returns a string representation of this number in an arbitrary base with a custom alphabet.
Because this method accepts an alphabet with any character, including dash, it does not handle negative numbers; a NegativeNumberException will be thrown when attempting to call this method on a negative number.
Parameters
string $alphabet The alphabet, for example '01' for base 2, or '01234567' for base 8.:
Throws
NegativeNumberException If this number is negative.
\InvalidArgumentException If the given alphabet does not contain at least 2 chars.
File
-
vendor/
brick/ math/ src/ BigInteger.php, line 942
Class
- BigInteger
- An arbitrary-size integer.
Namespace
Brick\MathCode
public function toArbitraryBase(string $alphabet) : string {
$base = \strlen($alphabet);
if ($base < 2) {
throw new \InvalidArgumentException('The alphabet must contain at least 2 chars.');
}
if ($this->value[0] === '-') {
throw new NegativeNumberException(__FUNCTION__ . '() does not support negative numbers.');
}
return Calculator::get()->toArbitraryBase($this->value, $alphabet, $base);
}