Difference between ‘>>’ and ‘>>>’ operators in java

www.l‮ttua‬uri.com
Difference between ‘>>’ and ‘>>>’ operators in java

Difference between right shift operator and unsigned right shift operator in Java:

>> is a right shift operator shifts

all of the bits in a value to the right to a specified number of times.
int a =15;
a= a >> 3;
The above line of code moves 15 three characters right.

>>> is an unsigned shift operator used to shift right.

The places which were vacated by shift are filled with zeroes

/**
 * @author lautturi.com
 * Java example: Difference between right shift operator and unsigned  right shift operator
 */

import java.util.*;

public class Lautturi {
	public static void main(String[] args) {

		int a = -3;
		int b = a >> 3;
		int c = a >>> 3;

		System.out.println("a:" + a);
		System.out.println("b:" + b);
		System.out.println("c:" + c);
	}
}

output:

a:-3
b:-1
c:536870911
Created Time:2017-09-04 20:55:02  Author:lautturi