Tuesday 2 August 2011

The shift operators

The shift operators, >>, >>>, and << work with integer primitives only; 
The >> right shift extends the sign so a negative number stays negative
The >>> operator shifts in zero bits, creating a positive number. 
The << left shift always shifts in zero bits at the least significant position.


Operator        Example         Result
  
<<              << 2          12
   

>>              ->> 2         -2
   

>>>             ->>> 2        1073741822


public class MainClass{
    public static void main(String[] argv){
        System.out.println(<< 2);
        System.out.println(->> 2);    
        System.out.println(->>> 2);    
    }
}

No comments:

Post a Comment