Bitwise operators allow you to turn specific bits within an
integer on or off. If both the left- and right-hand parameters are
strings, the bitwise operator will operate on the characters' ASCII
values.
Table 15-3. Bitwise Operators
| Example | Name | Result |
|---|
| $a & $b | And | Bits that are set in both $a and $b are set. |
| $a | $b | Or | Bits that are set in either $a or $b are set. |
| $a ^ $b | Xor |
Bits that are set in $a or $b but not both are set.
|
| ~ $a | Not |
Bits that are set in $a are not set, and vice versa.
|
| $a << $b | Shift left |
Shift the bits of $a $b steps to the left (each step means
"multiply by two")
|
| $a >> $b | Shift right |
Shift the bits of $a $b steps to the right (each step means
"divide by two")
|
| Warning |
Don't right shift for more than 32 bits on 32 bits systems. Don't left shift
in case it results to number longer than 32 bits.
|
Copyright © 1997 - 2007 by the PHP Documentation Group. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later. A copy of the Open Publication License is distributed with this manual, the latest version is presently available at http://www.opencontent.org/openpub/.
Please see full copyright text at http://www.php.net/manual/en/copyright.php
Original version of the above documentation is available at http://www.php.net/manual/en/