int a = 12; // binary: 1100 int b = 10; // binary: 1010 int andResult = a & b; int orResult = a | b; System.out.println("AND: " + andResult + ", OR: " + orResult);
The binary of 12 is 1100 and 10 is 1010.
AND operation: 1100 & 1010 = 1000 (decimal 8)
OR operation: 1100 | 1010 = 1110 (decimal 14)
int x = 5; // binary: 0101 int y = 3; // binary: 0011 int xorResult = x ^ y; int notX = ~x; System.out.println("XOR: " + xorResult + ", NOT x: " + notX);
5 in binary: 0101
3 in binary: 0011
XOR: 0101 ^ 0011 = 0110 (decimal 6)
NOT 5 flips bits: ~0101 = 1010 (in 32-bit signed int, this is -6)
int num = 16; // binary: 0001 0000 int leftShift = num << 2; int rightShift = num >> 3; System.out.println("Left Shift: " + leftShift + ", Right Shift: " + rightShift);
16 << 2 = 16 * 4 = 64
16 >> 3 = 16 / 8 = 2
-1 in binary (32-bit) is all 1s: 11111111 11111111 11111111 11111111
Applying ~ flips all bits to 0s: 00000000 00000000 00000000 00000000 which is 0, but since ~x = -x - 1, ~(-1) = 0
Wait, this is a trick: actually ~(-1) = 0, but the question asks for the result of ~(-1), which is 0.
Correction: The correct answer is 0, so option A.
int a = 9; // binary: 1001 int b = 14; // binary: 1110 int result = ((a & b) ^ (a | b)) << 1; System.out.println(result);
a & b = 1001 & 1110 = 1000 (8)
a | b = 1001 | 1110 = 1111 (15)
(a & b) ^ (a | b) = 8 ^ 15 = 7 (0111)
Left shift by 1: 7 << 1 = 14 (1110)
Wait, this is 14, but options show 28 as C.
Recalculate carefully:
8 ^ 15 = 7
7 << 1 = 14
So output is 14, option D.
But option D is 14, option D is 28.
Check if code is correct or if parentheses are different.
Code: ((a & b) ^ (a | b)) << 1
Yes, result is 14.
So correct answer is A.
