0 · Recall Warm-up
Answer from memory first. Answers are in the Answer Vault at the bottom.
- Booth action for the pair (1, 0)? from Lesson 1.1.3
- Overflow rule for signs? from Lesson 1.1.2
- Hex digit for 1101? from Lesson 0.1.2
1 · The Hook
🎣
A calculator shows decimal digits, so it often stores each digit separately in 4 bits (BCD). A rotating knob reports its angle with a code where neighbouring positions differ in only one bit (Gray code), so a half-read position is never wildly wrong. And a single extra bit (parity) can catch a flipped bit on a noisy wire. GATE asks conversions in all three.
2 · Predict First
🤔
Gray code for 0 to 3 is 00, 01, 11, 10. What do you notice about each step, including the step from 3 back to 0?
Make a guess in your head. The answer opens Section 3.
3 · Core Concept
💡
Predict First — the answer
Each step changes exactly one bit, even 10 → 00.
🗣️
In plain words
A code is an agreed way of writing information in bits. BCD writes each decimal digit in its own 4 bits. Excess-3 is BCD plus 3. Gray code orders patterns so neighbours differ in one bit. A parity bit makes the number of 1s even (or odd) so a single flipped bit shows up.
1. BCD (binary-coded decimal, 8421 code)
Each decimal digit → 4 bits: 59 → 0101 1001. (Plain binary would be 111011.)
- Only 10 of the 16 patterns are used; 1010 to 1111 are invalid.
- BCD addition: add each digit in binary; if a digit sum is more than 9 (or produces a carry), add 6 (0110) to correct it. 8 + 7: 1000 + 0111 = 1111 (> 9) → + 0110 = 1 0101 → BCD 0001 0101 (15).
- BCD needs more bits than binary: 2026 needs 16 bits in BCD (0010 0000 0010 0110) but 11 bits in binary.
2. Excess-3
Each digit + 3, then 4-bit binary: 59 → 8, 12 → 1000 1100. It is self-complementing: inverting the bits of a digit's code gives the code of 9 − digit (useful for subtraction).
3. Gray code
Consecutive numbers differ in exactly one bit.
- Binary → Gray: keep the MSB; each next Gray bit = XOR of the two neighbouring binary bits. In one formula: g = b ⊕ (b shifted right by 1). 5 = 101 → 1, 1⊕0, 0⊕1 → 111.
- Gray → binary: keep the MSB; each next binary bit = previous binary bit ⊕ current Gray bit. 1011 → 1, 1⊕0 = 1, 1⊕1 = 0, 0⊕1 = 1 → 1101.
| Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| Binary | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 |
| Gray | 000 | 001 | 011 | 010 | 110 | 111 | 101 | 100 |
(Gray code is also how K-maps in Phase 4 order their rows and columns.)
4. Parity
- Even parity: the parity bit makes the total number of 1s even. 1011001 has four 1s → parity bit 0.
- Odd parity: makes the total odd.
- A single parity bit detects any odd number of flipped bits but cannot locate or correct them, and misses two flips.
4 · Visual
Binary -> Gray for 1101 (13)
binary : 1 1 0 1
\ / \ / \ /
XOR : 0 1 1
Gray : 1 0 1 1 (MSB copied, then XOR of neighbours)
5 · Worked Examples
Example 1 Easy
Write 59 in BCD and in excess-3.
Solution
BCD 0101 1001; excess-3 1000 1100.
Example 2 Medium
Convert the Gray code 1011 to binary.
Solution
1, 1⊕0 = 1, 1⊕1 = 0, 0⊕1 = 1 → 1101 (13).
Example 3 GATE
In BCD addition, 4 + 5 and 8 + 7 are added digit-wise. Which needs the +6 correction?
Solution
4 + 5 = 9 (1001) is a valid digit: no correction. 8 + 7 = 15 (1111 > 9): add 0110.
6 · GATE Traps
⚠️
- BCD is digit by digit; don't convert the whole number to binary.
- Correction +6 is needed when a digit sum exceeds 9 or produces a carry (e.g. 9 + 9 = 1 0010).
- Gray → binary uses the previous binary bit, not the previous Gray bit.
- Parity detects odd numbers of errors only.
7 · Memory Hook
🧠
"BCD: 4 bits per digit, add 6 past 9. Gray: one bit changes, g = b ⊕ (b >> 1). Parity: count the 1s."
8 · Connect the Dots
Phase 1 is complete: integers, signed and coded. Real numbers like 3.75 or 0.1 need more: Phase 2 covers fixed-point fractions and the IEEE 754 floating-point format.
9 · Self-Test
GATE format. Try every question before opening the vault.
Q1MCQ1 markBCD
The BCD code for 2026 is:
- (A) 0010 0000 0010 0011
- (B) 0110 0010 0000 0010
- (C) 0111 1110 1010
- (D) 0010 0000 0010 0110
Q2NAT1 markInvalid BCD
How many of the 16 possible 4-bit patterns are not valid BCD digits?
Numerical answer: ________
Q3MCQ1 markGray code
The 4-bit Gray code for 13 (binary 1101) is:
- (A) 1101
- (B) 1011
- (C) 1110
- (D) 0111
Q4NAT2 marksGray to binary
The Gray code 1110 is converted to binary. What decimal value results?
Numerical answer: ________
Q5NAT1 markParity
An even-parity bit is added to the 7-bit data 1011001. What is the parity bit?
Numerical answer: ________
10 · Rule Card
- BCD: 4 bits per decimal digit; 1010–1111 invalid; digit sum > 9 or carry → add 0110.
- Excess-3: digit + 3; self-complementing.
- Gray: g = b ⊕ (b >> 1); back: bᵢ = bᵢ₊₁ ⊕ gᵢ (running XOR from the MSB). Neighbours differ in one bit.
- Even parity makes the count of 1s even; detects odd numbers of flipped bits.
11 · Concept Ledger
Unlocked in this lesson. From here on, these terms may be used.
binary-coded decimalinvalid BCD patternsBCD addition and the +6 correctionexcess-3 codeself-complementing codeGray codebinary to GrayGray to binaryeven and odd parityerror detection
12 · Answer Vault
Answer Vault
Try the questions first. Open when you are ready to check.
Recall Warm-up
- Subtract the multiplicand.
- Same-sign operands, opposite-sign result.
- D.
Self-Test
Q1 Answer: (D)1 mark
One 4-bit group per decimal digit.
- (A) is wrong: Last digit wrong.
- (B) is wrong: Reversed.
- (C) is wrong: That is binary 2026.
Re-read: Lesson 1.2.1 — Binary codes: BCD, excess-3, Gray code and parity
Q2 Answer: 61 mark
1010 to 1111.
Re-read: Lesson 1.2.1 — Binary codes: BCD, excess-3, Gray code and parity
Q3 Answer: (B)1 mark
1, 1⊕1 = 0, 1⊕0 = 1, 0⊕1 = 1.
- (A) is wrong: Plain binary.
- (C) is wrong: Wrong.
- (D) is wrong: Wrong.
Re-read: Lesson 1.2.1 — Binary codes: BCD, excess-3, Gray code and parity
Q4 Answer: 112 marks
1, 1⊕1 = 0, 0⊕1 = 1, 1⊕0 = 1 → 1011.
Re-read: Lesson 1.2.1 — Binary codes: BCD, excess-3, Gray code and parity
Q5 Answer: 01 mark
Four 1s already.
Re-read: Lesson 1.2.1 — Binary codes: BCD, excess-3, Gray code and parity