What is the difference between >> and >>>?


The >> operator carries the sign bit when shifting right. 

The >>> zero-fills bits that have been shifted right.


class NumTest
{
    public static void main(String[] args) throws Exception
    {
        int n=-8;
        int x=n>>3;
        int y=n>>>3;
        System.out.println(x);
        System.out.println(y);
    }
}

Output
-1
536870911


Comments