What is the '>>' operator for in Java?


I have a problem with the use of the character '>>' I would like to know what function it actually fulfills, which is what it does considering something like:

System.out.println(5>>1); the result is 2 but why? I understand that it is also called the Bit operator but it really compares the bits of these numbers and determines what?


To find out why, you have to pass the number 5 to binary: 00000101

The operator >> shifts X bits to the right depending on the number after the operator, in your case 1 bit , therefore 00000101 -> 00000010 which is 2

Scroll to Top