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:
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. Previous Comments: ------------------------------------------------------------------------ [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