File tree Expand file tree Collapse file tree 1 file changed +4
-7
lines changed Expand file tree Collapse file tree 1 file changed +4
-7
lines changed Original file line number Diff line number Diff line change @@ -116,17 +116,14 @@ public function __get(string $name)
116116 public function setValue (Content $ content )
117117 {
118118 $ binaryData = $ content ->getBinary ();
119- $ offsetIndex = 0 ;
120119 $ contentLength = $ this ->contentLength ->getLength ();
121- $ isNegative = (\ord ($ binaryData [$ offsetIndex ]) & 0x80 ) != 0x00 ;
122- $ number = gmp_init (\ord ($ binaryData [$ offsetIndex ++]) & 0x7F , 10 );
120+ $ isNegative = (\ord ($ binaryData [0 ]) & 0x80 ) != 0x00 ;
123121
124- for ($ i = 0 ; $ i < $ contentLength - 1 ; $ i ++) {
125- $ number = gmp_or (gmp_mul ($ number , 0x100 ), \ord ($ binaryData [$ offsetIndex ++]));
126- }
122+ $ number = gmp_import ($ binaryData , 1 , GMP_MSW_FIRST | GMP_BIG_ENDIAN );
127123
128124 if ($ isNegative ) {
129- $ number = gmp_sub ($ number , gmp_pow (2 , 8 * $ contentLength - 1 ));
125+ // For negative numbers in two's complement, we need to subtract 2^(bits)
126+ $ number = gmp_sub ($ number , gmp_pow (2 , 8 * $ contentLength ));
130127 }
131128
132129 $ this ->gmpValue = $ number ;
You can’t perform that action at this time.
0 commit comments