Difficulty: Easy
Correct Answer: 0100
Explanation:
Introduction / Context:
Gray code (also called reflected binary code) is a binary numeral system in which two successive values differ in only one bit. It is used in encoders, error minimization during transitions, and some communication schemes. This question asks for the 4-bit Gray code of decimal 7 and reinforces the conversion method between binary and Gray representations.
Given Data / Assumptions:
Concept / Approach:
The standard conversion from binary b to Gray g uses: g[n] = b[n] for the most significant bit and g[i] = b[i] XOR b[i+1] for remaining bits. Equivalently, g = b XOR (b >> 1). The inverse works by cumulative XOR from the MSB downward. Gray coding ensures single-bit transitions between adjacent integers, reducing ambiguity when bits change asynchronously.
Step-by-Step Solution:
Verification / Alternative check:
List Gray sequence for 0..7: 0000, 0001, 0011, 0010, 0110, 0111, 0101, 0100. The eighth entry corresponds to decimal 7 and is 0100, confirming the calculation.
Why Other Options Are Wrong:
0111, 1011, and 0101 do not match the computed Gray code for 7. 'None of the above' is wrong because a correct option exists (0100).
Common Pitfalls:
Confusing binary with Gray code, forgetting to pad to a uniform bit width, or performing XOR with the wrong alignment. Another frequent mistake is to flip only one bit from the binary number rather than applying the systematic XOR formula.
Final Answer:
0100
Discussion & Comments