What is the result of the following code execution:

public class MainClass {
    public static void main(String args[]){
        System.out.println((-(byte)128)>>>1 == 128 >>> 1);
    }
}
Explanation
The number 128 has a binary representation 00000000 00000000 00000000 10000000.
After the conversion into a byte it turns 10000000 - but in the byte type this binary representation corresponds to the number -128.
ā€“(ā€“128) gives 128, but 128>>>1 will be equal to 128>>>1.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback