Consider:
echo 50 >> 4;
Output:
3
Why does it output 3?
The >>
operator is called a binary right shift operator.
Shifting bits to the right 4 times is the same as dividing by two, four times in a row. The result, in this case would be 3.125
. Since 50 is an int, bit shifting will return the floor of this, which is 3
.
Put another way, 50
is 0b110010
in binary. Shifted 4 times we have 0b11
, which is 3
in decimal.