Updated fix for php.pear.net bug # 18015

toBits() on an object for which setPrecision(8) has been called should always return 8 bits.

As such we'll just iterate backwards instead of forward.
This commit is contained in:
terrafrost 2012-09-02 01:13:21 -05:00
parent 5de5d45bd5
commit 0f95ddc692

View File

@ -605,11 +605,11 @@ class Math_BigInteger {
{
$hex = $this->toHex($twos_compliment);
$bits = '';
for ($i = 0, $end = strlen($hex) & 0xFFFFFFF8; $i < $end; $i+=8) {
$bits.= str_pad(decbin(hexdec(substr($hex, $i, 8))), 32, '0', STR_PAD_LEFT);
for ($i = strlen($hex) - 8, $start = strlen($hex) & 7; $i >= $start; $i-=8) {
$bits = str_pad(decbin(hexdec(substr($hex, $i, 8))), 32, '0', STR_PAD_LEFT) . $bits;
}
if ($end != strlen($hex)) { // hexdec('') == 0
$bits.= str_pad(decbin(hexdec(substr($hex, $end))), strlen($hex) & 7, '0', STR_PAD_LEFT);
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');
}