note 12415 deleted from language.operators.bitwise by sniper
| From: | sniper@php.net | Date: | Mon, 13 Oct 2003 00:11:05 +0000 |
| Subject: | note 12415 deleted from language.operators.bitwise by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58401@lists.php.net to get a copy of this message | ||
Note Submitter: DanRichter.at.programmer.dot.net
----
The left-shift operator is actually a rotation operator (shifts with wrap-around), but the
right-shift operator is not. Examples:
echo ( 1 << 0 ); // Returns 1
echo ( 1 << 4 ); // Returns 16
echo ( 1 << 32 ); // Returns 1
echo ( 1 << 36 ); // Returns 16 [36 = 32 + 4]
echo ( 1 << 100 ); // Returns 16 [100 = 3*32 + 4]
echo ( 3 >> 1 ); // Returns 1
echo ( 3 >> 2 ); // Returns 0
echo ( (1<<31) << 1 ); // Returns 0 [1<<31 in binary is 1000...000, which is
negative; the shift by one ignores the sign bit and considers only the zeros]