mirror of
https://github.com/danog/PHPStruct.git
synced 2024-11-26 11:44:39 +01:00
Fixed precision problem in bindec function
This commit is contained in:
parent
cf6943cbe9
commit
e1cb9702b0
@ -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'));
|
||||
|
@ -724,7 +724,9 @@ class StructTools
|
||||
}
|
||||
|
||||
foreach (str_split(strrev($binary)) as $n => $bit) {
|
||||
$decimal += (pow(2, $n) * $bit);
|
||||
if ($bit == 1) {
|
||||
$decimal += (pow(2, $n) * $bit);
|
||||
}
|
||||
}
|
||||
|
||||
return $negative ? -$decimal : $decimal;
|
||||
|
Loading…
Reference in New Issue
Block a user