# Difference between the >> and >>> operators

a >> b will shift the number a by b bits to the right in an unsigned manner. It will always add a zero to the left side to fill up the spot that frees up.

a >>> b will shift the number a by b bits to the right in a signed manner. It will add a zero to the left side if a is positive, but add a one if a is negative as to keep it negative.

Right shifting by one will divide the number by two.
Check out the output of following example program to get the hang of it:

```public class Main {
public static void main(String []args) {
unsignedShift(123);
unsignedShift(-123);

signedShift(123);
signedShift(-123);
}

public static void unsignedShift(int n) {
System.out.println("Unsigned right shift of " + n);
System.out.println("  before: " + Integer.toBinaryString(n));
System.out.println("  after:  " + Integer.toBinaryString(n >>> 1));
}

public static void signedShift(int n) {
System.out.println("Signed right shift of " + n);
System.out.println("  before: " + Integer.toBinaryString(n));
System.out.println("  after:  " + Integer.toBinaryString(n >> 1));
}
}
```

```Unsigned right shift of 123
before: 00000000 00000000 00000000 01111011
after:  00000000 00000000 00000000 00111101  <-- added zero to the front
Unsigned right shift of -123
before: 11111111 11111111 11111111 10000101
after:  01111111 11111111 11111111 11000010  <-- added zero to the front making
the number positive!
Signed right shift of 123
before: 00000000 00000000 00000000 01111011
after:  00000000 00000000 00000000 00111101  <-- added zero to the front
because 123 is positive
Signed right shift of -123
before: 11111111 11111111 11111111 10000101
after:  11111111 11111111 11111111 11000010  <-- added one to the front keeping
the result negative
```