info@meritcampus.com    +91-85006-22255
...
`

Bitwise Operators
What will be the output of the following program?
`public class Bitwise {    public static void main(String[] args) {        int num1 = 0x000F;        int num2 = 0x2222;        int num3 = -14;        num3 >>= 2;        byte num4 = 15;        num4 >>= 10;        int num5 = 65;        num5 <<= (num2 & num1);        int num6 = 10;        int num7 = 3 << 3;        int num8 = 10 >> 1;        int num9 = (100 >>> 2) | (2 << 100);        System.out.print("Output is = " + ((num2 & num1) + num3 + num4 + num5 + num6 + num7 + num8 + num9));    }}`

 A. Output is = 0 B. Output is = 342 C. Output is = 354 D. Output is = 450 E. Some other output F. Compilation Error or Runtime Error
Topic:

### User comments below.All of them might not be correct.

ans must be C for the given prbm ..as we take num1 as 15 num2 as 8738 num3 as -14 and then num3>> by 2 means divide by 4 and then left lower limit as in case of -ve num so gives -4 and then num4 ryt shift by 10 so gives 0 ..so on.. so final values r 15 8738 -4 0 260 10 24 5 57 so gives output as C

Posted by Pramod Jain    2013-10-29 12:38:32

num1=15, num2=8738 num1&num2=2
num3=-4 as -14 right shifted by 2, num4=0, num5=260 as n2&n1 is 2 which is left shifted by 2, num6=10, num7=24 as 3 is shifted left 3 bits, num8=5 as 10 right shifted and num9=57 so the output is = 354.

Posted by Amar Kumar Biradar    2013-10-29 12:40:53

Ans is F.........compilation error , since in the line int num1,we should give 'int' value but here instead of 'int' ,'float' value is given,so it is precision error.

Posted by Ankit Mudiraj    2013-10-29 18:04:11

Congratulations Pramod Jain. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2013-10-30 08:56:54

thank u mc :) got rc :) :)

Posted by Pramod Jain    2013-12-03 04:38:02