Java programming — Evaluate bitwise operators step by step: class Bitwise { public static void main(String [] args) { int x = 11 & 9; int y = x ^ 3; System.out.println( y | 12 ); } }

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:

  • Compute x = 11 & 9.
  • Then y = x ^ 3.
  • Print y | 12.


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

More Questions from Operators and Assignments

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion