1
0
mirror of https://github.com/danog/phpseclib.git synced 2025-01-22 04:51:19 +01:00

Negative numbers should be prepended with a 0

This commit is contained in:
terrafrost 2012-09-02 11:06:53 -05:00
parent 0f95ddc692
commit c2c3e9420d

View File

@ -611,7 +611,13 @@ class Math_BigInteger {
if ($start) { // hexdec('') == 0
$bits = str_pad(decbin(hexdec(substr($hex, 0, $start))), 8, '0', STR_PAD_LEFT) . $bits;
}
return $this->precision > 0 ? substr($bits, -$this->precision) : ltrim($bits, '0');
$result = $this->precision > 0 ? substr($bits, -$this->precision) : ltrim($bits, '0');
if ($twos_compliment && $this->compare(new Math_BigInteger()) > 0 && $this->precision <= 0) {
return '0' . $result;
}
return $result;
}
/**