Bitwise Operators
A binary digit, which may be 1 or 0, is called a bit. Bitwise operators are similar to logical operators, but where logical operators work on TRUE and FALSE, bitwise operators view numbers from a binary perspective. When using logical operators, 1 and 10 are both TRUE, but to a bitwise operator 1 looks like 0001 and 10 looks like 1010. A logical AND of 1 and 10 results in TRUE. A bitwise AND of 1 and 10 results in 0. This is because each bit of the two numbers is compared by a bitwise AND. Table 2.7 lists PHP's bitwise operators.
See Table 2.8 for an example of a bitwise operation, which shows that (12 & 10) == 8. Matching bits are operated on. In the rightmost position 0 and 0 are operated on with a bitwise AND. The result ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access