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

Breadcrumb

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

function Calculator::twosComplement

Parameters

string $number A positive, binary number.:

1 call to Calculator::twosComplement()
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 600

Class

Calculator
Performs basic operations on arbitrary size integers.

Namespace

Brick\Math\Internal

Code

private function twosComplement(string $number) : string {
    $xor = \str_repeat("\xff", \strlen($number));
    $number ^= $xor;
    for ($i = \strlen($number) - 1; $i >= 0; $i--) {
        $byte = \ord($number[$i]);
        if (++$byte !== 256) {
            $number[$i] = \chr($byte);
            break;
        }
        $number[$i] = "\x00";
        if ($i === 0) {
            $number = "\x01" . $number;
        }
    }
    return $number;
}

API Navigation

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