PHP bit arithmetic
$a & $b and (bitwise AND)
$a | $b or (bitwise OR)
$a ^ $b Xor (Bitwise XOR)
~ $a not (bitwise non)
$a << $b shift left
$a >> $b shift right
Detailed
$a & $b Bitwise and set the bit to 1 in both $ A and $b to 1;
Example: & 12 = 8
10 1010
12 1100
1000 8
$a | $b bitwise OR put a $ A or $b in one of 1 for the set to 1;
Example: 10 | 12 = 14
10 1010
12 1100
1110 14
$a ^ $b Bitwise XOR OR
Example: 10 ^ 12
10 1010
12 1100
0110 6
~a is set to 0 for the 0 of the per-digit
Example: ~ =
10 1010 1111111111111111111111111111111111111111111111111111111111110101-11
$a << $b left move the $b of $ A to the left (each move represents a multiply by 2);
Example: 1 << 10 = 1024
1 (1) shift left 10 bit 10000000000 (1024)
Equivalent to the 1*2 10 times, PHP is not a power operation is really depressed.
$a >> $b Right Move the $b in $ A to the right (each move is represented by 2);
Example: 1024x768 << 2 = 1256
10000000000 (1024) Shift right 2 bits is 100000000 (256)
PHP for Operation $ A & $b and (bitwise VS) $a | $b or (bitwise OR) $a ^ $b Xor (Bitwise XOR) ~ $a not (bitwise non) $a << $b shift left $a >> $b shift right
Detailed $ A & $b bitwise set to 1 for Bits 1 in $ A and $b; Example: & 12 = 810 101012 1100 1000 8
$a | $b bitwise OR put a $ A or $b in one of 1 for the set to 1; Example: 10 | 12 = 1410 101012 1100 1110 14
$a ^ $b Bitwise XOR: 10 ^ 1210 101012 1100 0110 6
~a is set to 0 for the 0 of the per-bit non-set of $ A: ~ = 10 1010 1111111111111111111111111111111111111111111111111111111111110101-11
$a << $b left move the $b in $ A to the left (each move is multiplied by 2), for example: 1 << 10 = 10241 (1) Shift left 10 bits 10000000000 (1024) is equivalent to 1*2 10 times, PHP is not a power operation is really depressed.
$a >> $b Right Move the $b in $ A to the right (each move is represented by 2); For example: 2 << 2 = 125610000000000 (1024) Right-shift to the left-hand side is 100000000 (256)