2.01 BCD & Weighted Digital Codes
What is a Digital Code?
A Digital Code is a system of rules that assigns a unique pattern of binary bits (
0s and1s) to represent numbers, letters, symbols, or control commands.Unlike pure binary number systems used for arithmetic, binary codes are engineered for specialized digital tasks such as decimal displays, error detection, data transmission, and mechanical position sensing.
graph TD Codes[Binary Digital Codes] --> Weighted[Weighted Positional Codes] Codes --> NonWeighted[Non-Weighted Codes] Weighted --> BCD8421[BCD / 8421 Code] Weighted --> W2421[2421 Self-Comp Code] Weighted --> W5211[5211 Code] Weighted --> W8421N[84-2-1 Negative Weight Code] NonWeighted --> XS3[Excess-3 Self-Comp Code] NonWeighted --> Gray[Gray Code / Single-Bit Change] NonWeighted --> ErrorCtrl[Parity / Error Control Codes]
1. What is BCD (Binary Coded Decimal)?
Concept: BCD Definition
Binary Coded Decimal (BCD) is a class of binary encodings where each decimal digit of a number is represented by a fixed number of bits (usually four).
In standard 8421 BCD, each decimal digit (0 through 9) is directly replaced by its equivalent 4-bit binary nibble.
- Decimal:
- BCD:
Why do we use BCD?
- Decimal Display Drivers: Devices like calculators and digital clocks use 7-segment displays. Directly mapping 4-bit BCD nibbles to display segment controllers is much simpler than converting a pure binary number into decimal components.
- Financial Precision: In binary floating-point representations, decimal fractions like cannot be represented exactly (leading to rounding errors: ). BCD represents each decimal digit exactly, preventing precision loss in financial transactions.
2. BCD Addition Mechanics
Because a 4-bit binary group can represent 16 states ( to ), but BCD only permits 10 states ( to ), standard binary addition can yield invalid states.
The BCD Addition Rule:
- Add the two BCD digits using standard binary addition.
- Check the sum of each 4-bit nibble:
- Case A: Sum and no carry generated The sum is a valid BCD digit.
- Case B: Sum OR an intermediate carry is generated The sum is invalid. Add to that nibble to skip the 6 invalid states, and add the resulting carry to the next higher-order nibble.
Step-by-Step Addition Examples:
Example 1: BCD Addition with Sum (Valid)
Add and :
4_{10} \to & 0100 & (\text{BCD}) \\ +3_{10} \to & 0011 & (\text{BCD}) \\ \hline & 0111 & (\text{Binary Sum} = 7_{10} \le 9) \end{array}$$ Since the sum is $\le 9$ and no carry was generated, the result is valid: **$0111_{\text{BCD}} = 7_{10}$**.
Example 2: BCD Addition with Sum (Correction Needed)
Add and :
6_{10} \to & 0110 & (\text{BCD}) \\ +7_{10} \to & 0111 & (\text{BCD}) \\ \hline \text{Binary Sum} \to & 1101 & (\text{Equal to } 13_{10} > 9 \implies \text{Invalid}) \\ \text{Add } 6 \to &+0110 & (\text{Correction Factor}) \\ \hline \text{Result} \to & \mathbf{1 \ 0011} & (\text{Carry generated to next nibble}) \end{array}$$ Expressed as 4-bit groups: $\mathbf{0001\ 0011_{\text{BCD}}} = 13_{10}$.
3. Distinction Between a Number System and a Code
Major Exam Theory Question (PYQ 2018 — asked as the opening half of a 12-mark question)
Question (verbatim): Explain the distinction between number system and code with example.
| Aspect | Binary Number System | Binary Code |
|---|---|---|
| Fundamental Purpose | Designed for mathematical computation and quantitative representation. | Designed for human interface, data transmission, and hardware control. |
| Bit Position Weighting | Bit positions follow strict powers of 2 (). | Bit positions may have non-standard weights () or no weights at all. |
| Arithmetic Suitability | Directly supports standard addition, subtraction, and multiplication. | Unsuitable for direct arithmetic without specialized hardware conversion. |
| Bit Efficiency | Highly efficient; utilizes all binary combinations continuously. | Contains invalid/unused states {e.g., BCD skips 6 states out of 16}. |
| Representation Example |
4. Weighted Positional Codes
A digital code is classified as Weighted if each bit position in a 4-bit group is assigned a fixed numerical weight (). The represented decimal digit is calculated as:
Comparison Table of Major 4-Bit Weighted Codes:
| Decimal Digit | 8421 (Standard BCD) | 2421 Code | 5211 Code | 84-2-1 Code |
|---|---|---|---|---|
| 0 | 0000 | 0000 | 0000 | 0000 |
| 1 | 0001 | 0001 | 0001 | 0111 |
| 2 | 0010 | 0010 | 0011 | 0110 |
| 3 | 0011 | 0011 | 0101 | 0101 |
| 4 | 0100 | 0100 | 0111 | 0100 |
| 5 | 0101 | 1011 | 1000 | 1011 |
| 6 | 0110 | 1100 | 1001 | 1010 |
| 7 | 0111 | 1101 | 1011 | 1001 |
| 8 | 1000 | 1110 | 1101 | 1000 |
| 9 | 1001 | 1111 | 1111 | 1111 |
Verify any weighted-code row in 5 seconds
Multiply each bit by its weight and add. For the 5211 row of digit 8: ✓. Do this on every row you write in the exam — weighted-code tables are trivially self-checking, so there is no excuse for a wrong entry.
Note that 5211 is not unique: digit 7 can legally be written
1011() or1100(), since both evaluate to 7. Examiners accept any valid combination, but stay consistent within one answer.
Terminology & Concept Breakdown
- 8421 (BCD): The standard Binary Coded Decimal system. Uses standard binary weights for digits 0 to 9. States
1010to1111( to ) are invalid.- 2421 Code: A weighted self-complementing code where the sum of bit weights equals .
- 5211 Code: A weighted code where the MSB carries a weight of .
- 84-2-1 Code: A negative-weight code where the last two bits carry negative weights ( and ).
4.2 Differences between Weighted and Non-Weighted Codes
| Feature | Weighted Codes | Non-Weighted Codes |
|---|---|---|
| Bit Value Weighting | Each bit position is assigned a specific numerical weight (). | Bits have no position weights; the value depends strictly on pattern rules. |
| Mathematical Evaluation | . | Cannot be converted to decimal via standard sum of products. |
| Examples | 8421 (BCD), 2421, 5211, 84-2-1. | Excess-3, Gray Code. |
| Arithmetic Logic | Simple arithmetic correction rules can be applied (e.g. in BCD). | Complex arithmetic correction rules; Gray code is not suitable for direct addition. |
| Primary Applications | Display drivers, calculators, and ALU input interfaces. | Rotary encoders (Gray) and self-complementing math simplifications (Excess-3). |
5. Alphanumeric Codes: The ASCII Standard
Foundational Concept (Outside Direct PYQ Scope)
Alphanumeric representation via standard ASCII is a foundational computer organization topic that is rarely tested directly as calculation problems in ECE 2103 examinations, but is required context for digital systems.
Digital computers must process text, punctuation, and control symbols in addition to numbers. Alphanumeric Codes assign binary codes to represent characters. The most popular standard is ASCII (American Standard Code for Information Interchange).
5.1 Standard ASCII (7-Bit Code)
- Bit Count: Dedicated 7-bit word format ().
- State Space: Represents distinct characters (from decimal to ).
- Encoding Split:
- Printable Characters (): Includes digits
0-9, lettersa-zandA-Z, punctuation, and mathematical symbols. - Non-Printable Control Characters ( and ): Used for physical device control (e.g., Carriage Return
CR, Line FeedLF, BackspaceBS, NullNUL).
- Printable Characters (): Includes digits
5.2 Extended ASCII (8-Bit Code)
- Bit Count: 8-bit word format.
- State Space: Represents characters. The upper 128 characters (decimal ) represent special graphic characters, symbols, and foreign alphabet characters.
5.3 Hardware Storage & Parity Integration
In physical computer memory, data is organized in 8-bit bytes. Standard 7-bit ASCII characters are stored in 8-bit bytes by setting the most significant bit (MSB) to either:
0(default padding).- A Parity Bit (for simple error detection during transmission).
6. Multi-Digit Code Conversion
The examiner’s standard format is: “represent this decimal number in these three or four codes.” Each decimal digit is encoded independently into its own 4-bit group — you never convert the whole number at once, except in the one part that explicitly asks for a pure binary number.
Worked Exam Problem (PYQ 2018 — 12 marks)
Question (verbatim): Explain the distinction between number system and code with example. Convert the decimal number into following forms: (i) BCD code; (ii) 5211 code; and (iii) Gray code number.
(The theory half of this question is answered by the table in §3 above.)
(i) BCD (8421) — encode each digit separately:
(ii) 5211 code — again digit by digit, from the table:
(iii) Gray code number — note the wording change. “Gray code number” means convert the whole value to binary first, then binary → Gray. It is not digit-by-digit.
Step 1 — decimal to binary:
Step 2 — binary to Gray (MSB copies down, then ):
Binary: 1 0 0 1 0 1 1 1 0 1
\ \ \ \ \ \ \ \ \ \
Gray: 1 1 0 1 1 1 0 0 1 1
The trap in this question
Parts (i) and (ii) are digit-wise (three 4-bit groups); part (iii) is whole-number (one 10-bit string). Students who Gray-code each decimal digit separately lose the entire third part. The giveaway is the word “number” — BCD and 5211 are digit codes, Gray is a number code.
6.1 The Four-Format Variant
Worked Exam Problem (PYQ 2019 — 08 marks)
Question (verbatim): Represent the decimal number (i) in BCD, (ii) in excess-3 code, (iii) in 2,4,2,1 code, and (iv) as a binary number.
| Format | Method | Result |
|---|---|---|
| (i) BCD | Each digit → 8421 nibble | 1000 0110 0010 0000 |
| (ii) Excess-3 | Add 3 to each digit, then encode in binary | 1011 1001 0101 0011 |
| (iii) 2421 | Each digit → 2421 nibble from table | 1110 1100 0010 0000 |
| (iv) Binary | Convert the whole value | 10000110101100 |
Working for (ii): , , , . Working for (iv): .
Again, notice that (i)–(iii) are digit-wise and (iv) is whole-number — the same split that trips people up in the 2018 paper.
7. PYQ Master Puzzle: The 12-Bit Register Decoder
PYQ Master Puzzle (2022): The 12-Bit Register Decoder
Question: The state of a 12-bit register is
100010010111. What is its content if it represents: (i) Three decimal digits in BCD? (ii) Three decimal digits in the excess-3 code? (iii) Three decimal digits in the 8-4-2-1 code? (iv) A binary number?Solution Methodology: First, divide the 12-bit string into three 4-bit nibbles:
1000,1001,0111.(i) As BCD (Standard 8421): Evaluate each 4-bit block directly into decimal.
1000= 81001= 90111= 7- Answer: 897
(ii) As Excess-3 Code: Excess-3 is generated by adding 3 (
0011) to the decimal digit. To decode it, subtract 3 from each nibble.
1000(8) - 3 = 51001(9) - 3 = 60111(7) - 3 = 4- Answer: 564
(iii) As 8, 4, -2, -1 Code: Apply the specific mathematical weights to each bit in the nibble: .
1000= 81001= 70111= 1- Answer: 871
(iv) As a pure Binary Number: Evaluate the entire 12-bit string as a single base-2 integer.
- Answer: 2199
Past Year Questions (PYQs)
Question (as asked) Years Marks Solved in Distinction between number system and code, with example 2018 (part of 12) §3 Convert to BCD, 5211 code, and Gray code number 2018 12 §6 Represent in BCD, excess-3, 2421, and binary 2019 8 §6.1 12-bit register 100010010111read as BCD / excess-3 / 8-4-2-1 / binary2022 10 §7 Pattern to notice: every one of these is the same skill wearing a different hat — encode digit-wise into a 4-bit code, or convert the whole number. Learn the weighted-code table cold (and verify each row by weight-sum), and this becomes free marks. The reliable trap is mixing up digit-wise codes (BCD, excess-3, 2421, 5211, 84-2-1) with whole-number codes (Gray, pure binary).