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 (2018 - 4 Marks)
Question: Explain the fundamental differences between a Number System and a Code.
| 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 | 0100 | 0101 |
| 4 | 0100 | 0100 | 0101 | 0100 |
| 5 | 0101 | 1011 | 1000 | 1011 |
| 6 | 0110 | 1100 | 1001 | 1010 |
| 7 | 0111 | 1101 | 1011 | 1001 |
| 8 | 1000 | 1110 | 1100 | 1000 |
| 9 | 1001 | 1111 | 1111 | 1111 |
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 ).
5. PYQ Numerical Solution: 5211 Code Conversion
Major Exam Problem: Convert into 5211 Weighted Code (2018 - 8 Marks)
Solution:
To convert a multi-digit decimal number into 5211 code, convert each decimal digit independently into its corresponding 4-bit 5211 code group from the lookup table:
- Digit 6:
- Digit 0:
- Digit 5:
6. 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)
- [PYQ 2018]: Explain the difference between a Number System and a Code. (04 Marks)
- [PYQ 2018]: Convert decimal numbers into 5211 weighted code (e.g., ). (08 Marks)
- [PYQ 2019]: Conversions for BCD, 2421, 5211, and 84-2-1 codes. (08 Marks)
- [PYQ 2022]: 12-Bit Register Decoder puzzle (
100010010111in BCD, Excess-3, 8-4-2-1, Binary). (10 Marks)