math/bigint/Gmp.php
public static function fromBinaryString(string $bytes, bool $twosc = false) : math\interfaces\BigInt
    {
        $sign      = '';
        $bNegative = $twosc && (ord($bytes[0]) & 0x80);

        if ($bNegative) {
            $bytes = ~$bytes;
            $sign  = '-';
        }

        // We're going to use hexadecimal as base to use PHP's built-ins.
        // Not instantiating here just yet since we might need to subtract if we got the number in
        // two's complement (and the instances are immutable, ie. we're saving a wee bit overhead).
        $result = gmp_init($sign.bin2hex($bytes), 16);

        if ($bNegative) {
            $result = gmp_sub($result, '1');
        }

        return new static($result);
    }
public static function fromBinaryString(string $bytes, bool $twosc = false) : math\interfaces\BigInt
    {
        $sign      = '';
        $bNegative = $twosc && (ord($bytes[0]) & 0x80);

        if ($bNegative) {
            $bytes = ~$bytes;
            $sign  = '-';
        }

        // We're going to use hexadecimal as base to use PHP's built-ins.
        // Not instantiating here just yet since we might need to subtract if we got the number in
        // two's complement (and the instances are immutable, ie. we're saving a wee bit overhead).
        $result = gmp_init($sign.bin2hex($bytes), 16);

        if ($bNegative) {
            $result = gmp_sub($result, '1');
        }

        return new static($result);
    }
public static function fromBinaryString ( string $ bytes , bool $ twosc = false ) : math \ interfaces \ BigInt { $ sign = '' ; $ bNegative = $ twosc && ( ord ( $ bytes [ 0 ] ) & 0x80 ) ; if ( $ bNegative ) { $ bytes = ~ $ bytes ; $ sign = '-' ; } // We're going to use hexadecimal as base to use PHP's built-ins. // Not instantiating here just yet since we might need to subtract if we got the number in // two's complement (and the instances are immutable, ie. we're saving a wee bit overhead). $ result = gmp_init ( $ sign . bin2hex ( $ bytes ) , 16 ) ; if ( $ bNegative ) { $ result = gmp_sub ( $ result , '1' ) ; } return new static ( $ result ) ; }
Converts the binary string represented number into a BigInt instance representing the number
in decimal format.

@param   string      $bytes      The binary string representing the number.
@param   bool        $twosc      Whether the number is represented in two's complement form.
@return  math\interfaces\BigInt
Converts the binary string represented number into a BigInt instance representing the number in decimal format .