Difficulty: Easy
Correct Answer: 1010
Explanation:
Introduction / Context:
Gray code changes only one bit between successive values, reducing errors in position encoders and asynchronous signal transfers. Converting between binary and Gray is a common interview and lab exercise.
Given Data / Assumptions:
Concept / Approach:
Rules for binary → Gray: g3 = b3; g2 = b3 XOR b2; g1 = b2 XOR b1; g0 = b1 XOR b0. Apply bitwise XORs from the binary input to produce the Gray output.
Step-by-Step Solution:
Verification / Alternative check:
Reverse (Gray → Binary) to confirm: b3 = g3 = 1; b2 = b3 XOR g2 = 1 XOR 0 = 1; b1 = b2 XOR g1 = 1 XOR 1 = 0; b0 = b1 XOR g0 = 0 XOR 0 = 0 → 1100, matching the original.
Why Other Options Are Wrong:
Common Pitfalls:
Using XOR with the wrong neighbor bit or copying the binary number unchanged.
Final Answer:
1010
Discussion & Comments