function Calculator::toDecimal
Returns the positive decimal representation of a binary number.
Parameters
string $bytes The bytes representing the number.:
1 call to Calculator::toDecimal()
- Calculator::bitwise in vendor/
brick/ math/ src/ Internal/ Calculator.php - Performs a bitwise operation on a decimal number.
File
-
vendor/
brick/ math/ src/ Internal/ Calculator.php, line 646
Class
- Calculator
- Performs basic operations on arbitrary size integers.
Namespace
Brick\Math\InternalCode
private function toDecimal(string $bytes) : string {
$result = '0';
$power = '1';
for ($i = \strlen($bytes) - 1; $i >= 0; $i--) {
$index = \ord($bytes[$i]);
if ($index !== 0) {
$result = $this->add($result, $index === 1 ? $power : $this->mul($power, (string) $index));
}
if ($i !== 0) {
$power = $this->mul($power, '256');
}
}
return $result;
}