note 12414 deleted from language.operators.bitwise by sniper
| From: | sniper@php.net | Date: | Mon, 13 Oct 2003 00:10:46 +0000 |
| Subject: | note 12414 deleted from language.operators.bitwise by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58398@lists.php.net to get a copy of this message | ||
Note Submitter: DanRichter.at.programmer.dot.net
----
Bit shifting (at least in PHP4) seems to preserve the sign, except that a 1 shifted to the sign bit
makes a positive number negative. Examples:
echo ( 1 << 2 ); // Returns 4
echo ( -1 << 2 ); // Returns -4
echo ( -3 >> 1 ); // Returns -2
echo ( 1 << 31 ); // Returns -2147483648
echo ( (1<<31) >> 31 ); // Returns -1 [negative sign bit preserved on right shift].
echo (-1 >> 100); // Returns -1 [-1>>X = -1 for all X].