PHP Bitwise Operators
| Operator | Description | Result |
|---|---|---|
$a & $b | And | Bits that are set in both $a and $b are set. |
$a | $b | Or (inclusive or) | Bits that are set in either $a or $b are set. |
$a ^ $b | Xor (exclusive or) | Bits that are set in $a or $b but not both are set. |
$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”) |
~ $a | Not | Bits that are set in $a are not set, and vice versa. |
Bitwise operators allow evaluation and manipulation of specific bits within an integer. If both the left-hand and right-hand parameters are strings, the bitwise operator will operate on the characters’ ASCII values.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 bit. Use functions from the gmp extension ( gmp_and(), gmp_or(), gmp_xor(), gmp_testbit(), gmp_clrbit() ) for bitwise manipulation on numbers beyond PHP_INT_MAX.
[ Short URL ... ]









[...] Bitwise Operators [...]
[...] Testing odd or even numbers with modulo or php bitwise operators: [...]
Leave your response!
Recent Comments
Tags
Meta
Blogroll
Archives