Difficulty: Easy
Correct Answer: 14
Explanation:
Introduction / Context:This checks understanding of Java's bitwise AND (&), XOR (^), and OR (|) using small integers, and requires converting between decimal and binary mentally.
Given Data / Assumptions:
Concept / Approach:Use binary forms: AND keeps bits set in both, XOR keeps bits set in exactly one, OR keeps bits set in either.
Step-by-Step Solution:
11 in binary = 1011; 9 in binary = 1001; so 11 & 9 = 1001 (decimal 9).Then y = 9 ^ 3. Write 9 = 1001 and 3 = 0011. XOR => 1010 (decimal 10).Finally y | 12: 10 = 1010, 12 = 1100. OR => 1110 (decimal 14).Verification / Alternative check:Cross-check by quick calculator or mental recomputation of each bit position.
Why Other Options Are Wrong:They correspond to misapplying XOR or OR, or mixing decimal and binary values incorrectly.
Common Pitfalls:Confusing XOR with OR, or forgetting leading zeros in alignment when writing binary.
Final Answer:14
Discussion & Comments