0

I have a simple program here .I know it Shift right zero fill operator. The left operands value is moved right by the number of bits specified by the right operand and shifted values are filled up with zeros.

package com.demo.operator;
public class Test123 {

      public static void main(String args[]) {
         int a = 60;      
         int c = 0;

         c = a >>> 2;     
         System.out.println("a >>> 2 = " + c );
      }
    } 

Output:a >>> 2 = 15

Can anyone tell me .

How to give the output a >>> 2 = 15 ?

3 Answers3

5

>>> is the unsigned right shift operator. Since a is 60 and 60 is 111100 in binary, when you shift right twice you get 1111 which is 15.

Corey Ogburn
  • 24,072
  • 31
  • 113
  • 188
0
>>> is the logical (or unsigned) right shift operator.

lets x= 10000000 00000000 00000000 01100000

x >>> 4 then x = 00001000 00000000 00000000 00000110

you can see the rightmost sign bit is also getting shifted to wards right but this is not true for >>.

if x = 00000000 00000000 00000000 00111100 i.e. x = 60

now x>>>2 so x = 00000000 00000000 00000000 001111 which is x = 15.

Trying
  • 14,004
  • 9
  • 70
  • 110
-1

Check the docs for the Bitwise and Bit Shift Operators.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Freaky Thommi
  • 756
  • 7
  • 18