**& bitwise AND, same as unchanged, otherwise all counted as 0
| Bitwise OR,
^ Bitwise XOR, not the same is counted as 1**
PHP bitwise AND OR (^, &) operation is also a very common logic to determine the type, there are many new PHP novice may not be familiar with this, today combined with some code on the PHP and or operations to do some introduction, first of all, in PHP, the bitwise and mainly for the binary number operation:
<?php
$a = 1;
$b = 2;
$c = $a ^b;
echo $c//3
?>
Decimal 1 is converted into binary: 00000001
Decimal 2 is converted into binary: 00000010
The bitwise ^ 00000011, is the difference is counted as 1, and then:
<?php
$a = 1;
$b = 2;
echo $a & $c; 1
?>
Decimal 3 is converted into binary: 00000011
Decimal 1 is converted into binary: 00000001
Bitwise & 00000001, is the same single-digit constant, otherwise all counted as 0, the bitwise "&" After the return value is meaningless, is mainly used to determine whether a $ A is present in the $c, permission usage is more:
<?php
$my _privilege = 15; 1+2+4+8 has full privileges
$Pri = ";
$privilege _arr = Array (8=> ' increase ', 4=> ' delete ',2=> ' change ',1=> ');
foreach ($privilege _arr as $k = + $v) {
$k & $my _privilege && $Pri. = ' I have '. $v. ' Power <br> ';
}
Echo $Pri;
?>
A number of fields can be distinguished by a single value
> $a = Hexdec (' 0x10c04000 ');
> $b = ($a & 0x0ff00000) >20;
> $c = ($a & 0x000ff000) >12;
> var_dump ($a, $b, $c);
> Output:
> int 281034752
> int 12
> int 4
Bitwise VS, Bitwise XOR, bitwise inverse