private static function _encodeNegativeInteger(\GMP $num): string
    {
        $num = gmp_abs($num);
        // compute number of bytes required
        $width = 1;
        if ($num > 128) {
            $tmp = $num;
            do {
                $width++;
                $tmp >>= 8;
            } while ($tmp > 128);
        }
        // compute two's complement 2^n - x
        $num = gmp_pow("2", 8 * $width) - $num;
        $bin = gmp_export($num, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
        // if first bit is 0, prepend full inverted byte
        // to represent negative two's complement
        if (!(ord($bin[0]) & 0x80)) {
            $bin = chr(0xff) . $bin;
        }
        return $bin;
    }
private static function _encodeNegativeInteger(\GMP $num): string
    {
        $num = gmp_abs($num);
        // compute number of bytes required
        $width = 1;
        if ($num > 128) {
            $tmp = $num;
            do {
                $width++;
                $tmp >>= 8;
            } while ($tmp > 128);
        }
        // compute two's complement 2^n - x
        $num = gmp_pow("2", 8 * $width) - $num;
        $bin = gmp_export($num, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
        // if first bit is 0, prepend full inverted byte
        // to represent negative two's complement
        if (!(ord($bin[0]) & 0x80)) {
            $bin = chr(0xff) . $bin;
        }
        return $bin;
    }
private static function _encodeNegativeInteger ( \ GMP $ num ) : string { $ num = gmp_abs ( $ num ) ; // compute number of bytes required $ width = 1 ; if ( $ num > 128 ) { $ tmp = $ num ; do { $ width ++ ; $ tmp >>= 8 ; } while ( $ tmp > 128 ) ; } // compute two's complement 2^n - x $ num = gmp_pow ( "2" , 8 * $ width ) - $ num ; $ bin = gmp_export ( $ num , 1 , GMP_MSW_FIRST | GMP_BIG_ENDIAN ) ; // if first bit is 0, prepend full inverted byte // to represent negative two's complement if ( ! ( ord ( $ bin [ 0 ] ) & 0x80 ) ) { $ bin = chr ( 0xff ) . $ bin ; } return $ bin ; }
Encode negative integer to DER content.

@param \GMP $num
@return string
Encode negative integer to DER content .