Difference between >> and >>> operators in java

Difference between >> and >>> operators in java

operator name

>>right shift operator
>>>unsigned shift operator

>>

>>shifts all of the bits in a value to the right to a specified number of times.

example:

refer ‮:ot‬lautturi.com
public static void main(String[] args) {
		int a = -2;
		a= a >> 3;
		
		System.out.printf("%d",a);
	}
	
11111111111111111111111111111110‬  <--right shift 3 times
11111111111111111111111111111111‬

output:

-1

>>>

When using >>>the places which were vacated by shift are filled with zeroes.

example:

public static void main(String[] args) {
		int a = -2;
		a= a >>> 3;
		
		System.out.printf("%d",a);
	}
	
11111111111111111111111111111110‬
‭00011111111111111111111111111111‬

output:

536870911
Created Time:2017-08-29 19:18:37  Author:lautturi