#32700 [Opn->Bgs]: unpack() returns signed values when it shouldn't

From: Date: Wed, 13 Apr 2005 20:54:13 +0000
Subject: #32700 [Opn->Bgs]: unpack() returns signed values when it shouldn't
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-77482@lists.php.net to get a copy of this message
ID: 32700 Updated by: derick@php.net Reported By: ieure@php.net -Status: Open +Status: Bogus Bug Type: Unknown/Other Function Operating System: Linux PHP Version: 4.3.10 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2005-04-13 22:49:33] ieure@php.net 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

« previous php.bugs (#77482) next »