Bitwise Operators¶
Bitwise operators evaluate specific bits within an integer.
Bitwise operators are convenient to handle bit fields.
&,&=: ampersand operator, and|,|=: pipe operator, or^,^=: caret operator, xor
All these operators have a short assignation version, as shown above.
These operator differ from logical operators, which convert the value to boolean before manipulation.
<?php
$a = 3; // binary : 11
$b = 7; // binary : 111
print $a & $b; // 3; binary : 11
?>
See also Are Bitwise Operators Still Relevant in Modern PHP? and Bitmasks and Bitwise Operators in PHP.
Related : Logical Operators, Logical Operators, And Operator, Logical Operators, Short Assignations, Bitfield, Boolean, Bitmask, Bitshift Operators, Letter Logical Bug, Pipe Operator