ID: 32700 User updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] -Status: Bogus +Status: Open Bug Type: Unknown/Other Function Operating System: Linux PHP Version: 4.3.10 New Comment:
It has nothing do with "echo showing the signed version." If that were the case, it would output the same (negative) number when you echo $before as well. It's PHP /using/ the signed version. For example: $test[$before] = 'It works!'; if (isset($test[$after])) { echo "It works!\n"; } else { echo "It doesn't work!\n"; } $before and $after are /not/ the same value to PHP. Nothing to do with echo. Previous Comments: ------------------------------------------------------------------------ [2005-04-13 23:07:10] [EMAIL PROTECTED] Yes, but echo will show the signed representatation. This is *not* a bug, use printf("%u") to show the unsigned version. ------------------------------------------------------------------------ [2005-04-13 23:01:54] [EMAIL PROTECTED] While PHP may only support signed integers, the manual for pack() clearly states, regarding the 'N' format: "unsigned long (always 32 bit, big endian byte order)" But it returns a signed int when using this format, contrary to the documentation. There's obviously some sort of internal PHP state regarding the signedness of a particular value, since it's capable of correctly representing the unsigned value. It just seems that unpack() is doing something wrong here. ------------------------------------------------------------------------ [2005-04-13 22:54:41] [EMAIL PROTECTED] try printf("%u") though to print it - that would work... ------------------------------------------------------------------------ [2005-04-13 22:54:12] [EMAIL PROTECTED] Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php PHP only supports signed integers. ------------------------------------------------------------------------ [2005-04-13 22:49:33] [EMAIL PROTECTED] Description: ------------ unpack() returns signed long values when the high bit is set, even though the unpack format is set to unsigned long. Workaround: $foo = unpack('N', $data); $foo = $foo << 1 >> 1; $foo += 0x80000000; Reproduce code: --------------- // High bit is set. $before = 0x80000002; echo "Before: $before\n"; // Outputs '2147483650' $int = pack('N', $before); $res = unpack('N', $int); $after = $res[1]; echo "After: $after\n"; // Outputs '-2147483646' Expected result: ---------------- $before and $after should be the same number. Actual result: -------------- $after is treated as signed, and does not equal $before. Script output: Before: 2147483650 After: -2147483646 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=32700&edit=1