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 and 1s) 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?

  1. 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.
  2. 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:

  1. Add the two BCD digits using standard binary addition.
  2. 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.

AspectBinary Number SystemBinary Code
Fundamental PurposeDesigned for mathematical computation and quantitative representation.Designed for human interface, data transmission, and hardware control.
Bit Position WeightingBit positions follow strict powers of 2 ().Bit positions may have non-standard weights () or no weights at all.
Arithmetic SuitabilityDirectly supports standard addition, subtraction, and multiplication.Unsuitable for direct arithmetic without specialized hardware conversion.
Bit EfficiencyHighly 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 Digit8421 (Standard BCD)2421 Code5211 Code84-2-1 Code
00000000000000000
10001000100010111
20010001000110110
30011001101000101
40100010001010100
50101101110001011
60110110010011010
70111110110111001
81000111011001000
91001111111111111

Terminology & Concept Breakdown

  • 8421 (BCD): The standard Binary Coded Decimal system. Uses standard binary weights for digits 0 to 9. States 1010 to 1111 ( 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:

  1. Digit 6:
  2. Digit 0:
  3. 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 = 8
  • 1001 = 9
  • 0111 = 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 = 5
  • 1001 (9) - 3 = 6
  • 0111 (7) - 3 = 4
  • Answer: 564

(iii) As 8, 4, -2, -1 Code: Apply the specific mathematical weights to each bit in the nibble: .

  • 1000 = 8
  • 1001 = 7
  • 0111 = 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 (100010010111 in BCD, Excess-3, 8-4-2-1, Binary). (10 Marks)