Difficulty: Medium
Correct Answer: 102 0 38
Explanation:
Introduction / Context:
This snippet combines bitwise NOT (~), left and right shifts, and type promotion rules for byte in C#. Predicting the output requires careful attention to how shift counts work and how casting back to byte truncates.
Given Data / Assumptions:
Concept / Approach:
Compute each line independently, remembering promotions and shift-count masking.
Step-by-Step Solution:
Verification / Alternative check:
Use a small console program to print each intermediate value in hex and decimal; confirm 0x66, 0x00, 0x26.
Why Other Options Are Wrong:
They miscompute the complement, ignore shift-count masking, or mis-handle the cast back to byte.
Common Pitfalls:
Forgetting that shifting by a large number is masked mod 32 for int; expecting left shift to wrap instead of truncating when cast back to byte.
Final Answer:
102 0 38
Discussion & Comments