What does >> mean in PHP?

后端 未结 8 1864
天涯浪人
天涯浪人 2021-02-19 05:13

Consider:

echo 50 >> 4;

Output:

3

Why does it output 3?

8条回答
  •  情书的邮戳
    2021-02-19 05:46

    >> is the binary right-shift operator.

    Your statement shifts the bits in the numeric value 50 four places to the right. Because all integers are represented in two's complement, this equals 3. An easy way to remember this is that one shift to the right is the same as dividing by 2, and one shift to the left is the same as multiplying by 2.

提交回复
热议问题