PHP/Operator/Bitwise Operators
Bitwise Operators
<source lang="html4strict">
Example Operation Result $a & $b And Bits that are set in both $a and $bare set. $a | $b Or Bits that are set in either $a or $bare set. $a ^ $b Xor Bits that are set in $$aor $b but not in 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 $ato the left $b steps. $a >> $b Shift right Shift the bits of $ato the right $b steps.
</source>
Bitwise operators in action
<source lang="html4strict">
<?php
$answers = 88; $question_four = 8; $answers = $answers ^ $question_four; print($answers . "
"); $answers = $answers | $question_four; print($answers . "
"); $answers = $answers ^ $question_four; print($answers . "
");
?>
</source>
Bitwise Operators summary table
<source lang="html4strict">
Operation Operator Class Associativity Example Bitwise AND & Binary Left $a & $b Bitwise | Binary Left $a | $b inclusive OR Bitwise exclusive ^ Binary Left $a ^ $b OR (XOR) Bitwise NOT ~ Unary Right ~$a Bitwise << Binary Left $a << $b left-shift Bitwise >> Binary Left $a >> $b right-shift
</source>