Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Calculator.php

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\Internal

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal