php bitwise operators
|
|
|
Question / Problem
|
what is the output of 2^2 in PHP?
|
Solution
|
^ is the bit wise operator in PHP, make a expression of eXclusive OR (XOR).
for eXclusive OR, it works with binary format of decimal numbers. if any one of the bit is 1 and other is 0 then it returns 1 otherwise it returns 0.
Reference Table in bit:
A B A^B 0 0 0 0 1 1 1 0 1 1 1 0
so here 2^2 => (0010) ^ (0010) = (0000) => 0
for any same number eXclusive OR returns 0. please check this out by 3^3, 4^4.
|
Applies to |
|
PHP
|
Rank It |
|