-2

I found this example and i can't understand the result :

$x = 5;
echo $x>>2;

output :

1

Can you explained for me please Thanks

medzbakh
  • 43
  • 3

1 Answers1

2

$a >> $b Shift right Shift the bits of $a $b steps to the right (each step means "divide by two")

So if 5 in binary is: 101

5>>1 is 2 in binary 10

5>>2 is 1 in binary 1

This operator if common in other languages such as C.

Source

ganchito55
  • 3,559
  • 4
  • 25
  • 46