C# bitwise operations output — evaluate AND and XOR on bytes byte b1 = 0xF7; byte b2 = 0xAB; byte temp; temp = (byte)(b1 & b2); Console.Write(temp + ' '); temp = (byte)(b1 ^ b2); Console.WriteLine(temp);

Difficulty: Easy

Correct Answer: 163 92

Explanation:


Introduction / Context:
This snippet tests understanding of bitwise AND (&) and XOR (^) on byte values and how hexadecimal translates to decimal output.



Given Data / Assumptions:

  • b1 = 0xF7 (247 decimal) → 11110111.
  • b2 = 0xAB (171 decimal) → 10101011.
  • Console prints decimal values of temp.


Concept / Approach:
Perform bitwise operations bit-by-bit:



Step-by-Step Solution:

AND: 11110111 & 10101011 = 10100011 = 0xA3 = 163.First print → "163 ".XOR: 11110111 ^ 10101011 = 01011100 = 0x5C = 92.Second print (with newline) → "92".


Verification / Alternative check:
Compute using a calculator in programmer mode; confirm 0xF7 & 0xAB = 0xA3 and 0xF7 ^ 0xAB = 0x5C.



Why Other Options Are Wrong:
They invert the order or provide results inconsistent with AND/XOR truth tables.



Common Pitfalls:
Confusing decimal vs. hex outputs; remember Console.Write on a byte prints its decimal numeric value by default.



Final Answer:
163 92

Discussion & Comments

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