1
0
mirror of https://github.com/danog/PHPStruct.git synced 2024-11-26 19:54:38 +01:00

Fixed precision problem in bindec function

This commit is contained in:
danogentili 2016-08-14 18:42:33 +02:00
parent cf6943cbe9
commit e1cb9702b0
2 changed files with 4 additions and 2 deletions

View File

@ -5,7 +5,7 @@ require 'lib/danog/PHP/StructTools.php';
require 'lib/danog/PHP/StructClass.php';
require 'lib/danog/PHP/StructException.php';
require 'lib/danog/PHP/Struct.php';
var_dump(bin2hex(pack('J', 18446744073709550590)));
var_dump(bin2hex(pack('J', "18446744073709550591")));
var_dump(bin2hex(\danog\PHP\Struct::pack('Q', 18446744073709550590)));
var_dump(\danog\PHP\Struct::calcsize('>l'));

View File

@ -724,8 +724,10 @@ class StructTools
}
foreach (str_split(strrev($binary)) as $n => $bit) {
if ($bit == 1) {
$decimal += (pow(2, $n) * $bit);
}
}
return $negative ? -$decimal : $decimal;
}