1

Why does it yield two different results if in both cases we are performing 32 bits unsigned right shift?

public class Main {
    public static void main(String[] args) {
        int i = -1;
        i = i>>>31;
        i = i>>>1;
        
        int j = -1;
        j = j>>>32;
        
        System.out.println(i);
        System.out.println(j);
    }
}

Output is:

0
-1
mp3001
  • 29
  • 4
  • 3
    before shifting, the shift is taken `% 32` (see [JLS, §15.19](https://docs.oracle.com/javase/specs/jls/se16/html/jls-15.html#jls-15.19)). So `j>>>32` is equivalent to `j>>>0` – Turing85 Aug 19 '21 at 19:31

0 Answers0