Question E8C09:
Which digital code allows only one bit to change between sequential code values?  

Choices:  
A: Binary Coded Decimal Code  
B: Extended Binary Coded Decimal Interchange Code  
C: Extended ASCII  
D: Gray code    

Correct Answer is  D: Gray code  

Correct answer: D — Gray code

Why it’s correct:
- Gray code (reflected binary) orders code words so that adjacent values differ by exactly one bit.  
- This minimizes ambiguity during transitions (e.g., in encoders or A/D converters) because only one bit can be in transition at a time.
- In terms of Hamming distance, adjacent codes satisfy:
  $$d_H(x_{k}, x_{k+1}) = 1$$
- Example (3-bit Gray sequence): 000, 001, 011, 010, 110, 111, 101, 100

Why the others are incorrect:
- Binary Coded Decimal (BCD): Encodes each decimal digit in 4 bits; adjacent decimal values can change multiple bits (e.g., 7 → 8: 0111 → 1000 changes 4 bits).
- Extended Binary Coded Decimal Interchange Code (EBCDIC): An 8-bit character set; ordering is not designed for single-bit adjacency.
- Extended ASCII: Also an 8-bit character set; no guarantee that adjacent codes differ by one bit.

Useful formulas and conversions:
- Hamming distance between two code words $x$ and $y$:
  $$d_H(x,y) = \text{number of bit positions where } x \neq y$$
- Binary to Gray (bitwise XOR):
  $$g_n = b_n,\quad g_i = b_{i+1} \oplus b_i \text{ for } i = n-1,\dots,0$$
- Gray to Binary (cumulative XOR):
  $$b_n = g_n,\quad b_i = b_{i+1} \oplus g_i \text{ for } i = n-1,\dots,0$$

Rule of thumb:
- Use Gray code when reading mechanical or asynchronous digital positions to avoid multi-bit transition errors.