Operators and Assignments

Q1: What will be the output of the program?
class BitShift 
{
    public static void main(String [] args) 
    {
        int x = 0x80000000;
        System.out.print(x + ' and  ');
        x = x >>> 31;
        System.out.println(x);
    }
}

A -2147483648 and 1

B 0x80000000 and 0x00000001

C -2147483648 and -1

D 1 and -2147483648

ANS:A - -2147483648 and 1

Option A is correct. The >>> operator moves all bits to the right, zero filling the left bits. The bit transformation looks like this: Before: 1000 0000 0000 0000 0000 0000 0000 0000 After: 0000 0000 0000 0000 0000 0000 0000 0001 Option C is incorrect because the >>> operator zero fills the left bits, which in this case changes the sign of x, as shown. Option B is incorrect because the output method print() always displays integers in base 10. Option D is incorrect because this is the reverse order of the two output numbers.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.