The Right Shift

The right shift operator, >>, shifts all of the bits in a value to the right a specified number of times. Its general form is shown here:

  value >> num  

num specifies the number of positions to right-shift.

The following code fragment shifts the value 32 to the right by two positions:

public class Main {
  public static void main(String[] argv) {

    int a = 32;
    a = a >> 2;
    System.out.println("a is " + a);

  }
}

The output:


a is 8

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.