Chapter 2: Digital Codes & Error Detection - Complete Study Notes

NotebookLM Ingestion Compilation

This merged document contains all 4 study notes for Chapter 2: Digital Codes & Error Detection from ECE 2103 Digital Electronics (Sharif Sir).


Related Concepts: 02 Excess-3 Code & Self-Complementing Logic | 03 Gray Code & Code Conversions | 04 Error Control, Parity Generators & Checkers

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. 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

2. 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 ).

3. 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:


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)

Related Concepts: 01 BCD & Weighted Digital Codes | 03 Gray Code & Code Conversions | 04 Error Control, Parity Generators & Checkers

2.02 Excess-3 Code & Self-Complementing Logic

What is a Self-Complementing Code?

A 4-bit binary code is defined as Self-Complementing if the 1’s complement {bitwise inversion: } of any decimal digit’s code word yields the exact code word of its 9’s decimal complement ().

graph LR
    subgraph Self-Complementing Symmetry
        D2[Decimal Digit 2: 0101] -->|Bitwise Inversion| InvD2[1's Comp: 1010]
        InvD2 -->|Equals| D7[Decimal Digit 7 = 9 - 2: 1010]
    end

1. Mathematical Proof: Excess-3 is a Self-Complementing Code

Major Exam Proof (2021, 2023, 2025 - 8 to 10 Marks)

Question: Prove mathematically that Excess-3 (XS-3) code is a self-complementing code.

Step-by-Step Proof:

  1. Definition of Excess-3 Code: The Excess-3 code word for any decimal digit () is constructed by adding to its standard 4-bit binary equivalent:

  2. Evaluating the 9’s Complement of (): The Excess-3 code word for the 9’s complement of is:

  3. Evaluating the 1’s Complement of : Taking the bitwise 1’s complement of a 4-bit number is mathematically equivalent to subtracting it from (): Substituting :

  4. Comparing Results:


2. Complete 9’s Complement Symmetry Table

Decimal Digit ()BCD (8421)Excess-3 Code ()1’s Comp of XS-39’s Comp Digit ()XS-3 Code of ()
000000011110091100
100010100101181011
200100101101071010
300110110100161001
401000111100051000
501011000011140111
601101001011030110
701111010010120101
810001011010010100
910011100001100011

3. Design: BCD to Excess-3 Code Converter

Major Exam Design Problem (2018 - 10 Marks)

Question: Design a combinational logic circuit to convert a 4-bit BCD input () to a 4-bit Excess-3 code output ().

Boolean Function Derivation (K-Map Simplification):

  • Inputs: (Don’t care conditions ).
  • Outputs: .
  1. Output (LSB):
  2. Output :
  3. Output :
  4. Output (MSB):

Past Year Questions (PYQs)

  • [PYQ 2017, 2021, 2023, 2025]: Define self-complementary code. (04 Marks)
  • [PYQ 2021, 2023, 2025]: Prove mathematically that Excess-3 code is a self-complementary code. (08-10 Marks)
  • [PYQ 2018]: Design a BCD to Excess-3 code converter circuit. (10 Marks)

Related Concepts: 01 BCD & Weighted Digital Codes | 02 Excess-3 Code & Self-Complementing Logic | 04 Error Control, Parity Generators & Checkers

2.03 Gray Code & Code Conversions

What is Gray Code?

Gray Code {also called Reflected Binary Code} is a 4-bit (or -bit) non-weighted binary coding system.

Its defining property is: “A binary coding system in which ONLY ONE BIT changes at a time between any two consecutive code words.”


1. Why is it Called “Reflected” Code?

The code is named “reflected” because the sequence of code words for the second half of any -bit Gray code sequence is the exact mirror image {reflection} of the first half, with the exception of the MSB which is inverted from 0 to 1.

2-Bit Gray Code Reflection Example:
Decimal 0:  0 0  ---| First half (MSB = 0)
Decimal 1:  0 1  ---|
-------------------- Reflection Axis
Decimal 2:  1 1  ---| Second half (MSB = 1, LSB reflected: 1 then 0)
Decimal 3:  1 0  ---|

2. Conversion Algorithms

Conversions between pure Binary and Gray code rely entirely on the Exclusive-OR (XOR, ) operation.

graph TD
    subgraph Binary to Gray Algorithm
        B3[B3 MSB] --> G3[G3 = B3]
        B3 & B2[B2] -->|XOR| G2[G2 = B3 ⊕ B2]
        B2 & B1[B1] -->|XOR| G1[G1 = B2 ⊕ B1]
        B1 & B0[B0 LSB] -->|XOR| G0[G0 = B1 ⊕ B0]
    end
graph TD
    subgraph Gray to Binary Algorithm
        g3[G3 MSB] --> b3[B3 = G3]
        b3 & g2[G2] -->|XOR| b2[B2 = B3 ⊕ G2]
        b2 & g1[G1] -->|XOR| b1[B1 = B2 ⊕ G1]
        b1 & g0[G0 LSB] -->|XOR| b0[B0 = B1 ⊕ G0]
    end

A. Binary to Gray Code Conversion

Given an -bit Binary number (), compute Gray bits ():

  • MSB Rule:
  • Subsequent Bits Rule: for .

B. Gray Code to Binary Conversion

Given an -bit Gray code (), compute Binary bits ():

  • MSB Rule:
  • Subsequent Bits Rule: for .

3. Design: 4-Bit Reflected Code to Binary Converter Circuit

Major Exam Design Problem (2024 - 10 Marks)

Question: Design a combinational logic circuit that converts a 4-bit reflected code (Gray code) number to a 4-bit binary number using XOR gates.

Circuit Equations & Architecture:

The circuit consists of a cascading chain of three 2-input XOR gates:

  • passes straight to output .
  • .
  • .
  • .

Past Year Questions (PYQs)

  • [PYQ 2017]: Define Reflected code. (04 Marks)
  • [PYQ 2018]: Convert into Gray code number. (Binary: ). (12 Marks)
  • [PYQ 2024]: Design a 4-bit reflected code to binary converter circuit using XOR gates. (10 Marks)

Related Concepts: 01 BCD & Weighted Digital Codes | 02 Excess-3 Code & Self-Complementing Logic | 03 Gray Code & Code Conversions

2.04 Error Control, Parity Generators & Checkers

Error Control Concepts

During serial data transmission over noisy communication channels, electromagnetic interference can cause bit inversion errors { or }.

To safeguard data integrity, systems employ Error Control Codes by appending redundant check bits to transmitted data packets.


1. Error Detecting vs. Error Correcting Codes

Major Exam Theory Question (2017, 2018 - 4 Marks)

Question: Explain the fundamental differences between Error Detecting codes and Error Correcting codes.

ParameterError Detecting CodesError Correcting Codes
Primary FunctionDetects the presence of errors during transmission.Detects the error AND automatically determines its bit location to correct it.
Action on ErrorFlags error to receiver; requires retransmission.Automatically corrects error without requesting retransmission.
Redundancy OverheadLow overhead; requires few redundant bits {e.g., 1 parity bit}.High overhead; requires multiple redundant check bits {e.g., Hamming distance}.
Implementation ComplexitySimple hardware {cascaded XOR gates}.Complex logic {syndrome decoders & bit-flipping networks}.
Standard ExamplesParity bits, Checksums, CRC.Hamming Code, Reed-Solomon Code, BCH Code.

2. Parity Architecture & Operation

graph LR
    subgraph Transmitter End
        DataTx[Data Bits: x y z] --> GenXOR[Parity Generator Logic]
        GenXOR --> Packet[Transmitted Packet: x y z P]
    end
    
    Packet -->|Serial Channel| RxPacket[Received Packet: x' y' z' P']
    
    subgraph Receiver End
        RxPacket --> CheckXOR[Parity Checker Logic]
        CheckXOR -->|C = 0| NoError[No Error Detected]
        CheckXOR -->|C = 1| ErrorDet[Bit Error Flagged!]
    end

3. Even Parity Generator & Checker

  • Even Parity Rule: The parity bit is generated so that the total count of 1s in is always EVEN.
  • 3-Bit Generator (Transmitter):
  • 4-Bit Checker (Receiver):

4. Design: 3-Bit Odd Parity Generator & 4-Bit Checker

Major Exam Design Problem (2022 - 8 Marks, 2025 - 10 Marks)

Question: Design a 3-bit parity generator and 4-bit parity checker circuit using an odd parity bit.

Part A: 3-Bit Odd Parity Generator (Transmitter)

  • Logic Rule: Generates such that total 1s in is ODD. If has an even number of 1s, must be 1.

Truth Table:

Input Message ()Generated Odd Parity Bit ()
0 0 01
0 0 10
0 1 00
0 1 11
1 0 00
1 0 11
1 1 01
1 1 10

Boolean Function:

The minterms for are , which is the exact inverse of a 3-input XOR function {an XNOR function}:


Part B: 4-Bit Odd Parity Checker (Receiver)

  • Logic Rule: Evaluates received bits . If total 1s is EVEN, an error has occurred Error output .

Boolean Function:

Implemented by cascading three 2-input XNOR gates.


5. Critical Limitations of Parity Error Checking

Limitations of Simple Parity

  1. Odd-Bit Error Detection Only: Parity can ONLY detect an odd number of bit errors {1, 3, 5 flipped bits}.
  2. Fails on Even-Bit Errors: If an even number of bits flip {e.g., 2 bits change state}, total parity remains unchanged, and remains {error undetected}.
  3. No Correction Capability: Parity indicates that an error occurred, but cannot identify which bit flipped.

Past Year Questions (PYQs)

  • [PYQ 2017]: Define Error Detection Code. (04 Marks)
  • [PYQ 2018]: Differences between Error Detecting and Error Correcting codes. (04 Marks)
  • [PYQ 2015, 2020, 2023, 2024]: 4-bit even parity checker design. (08 Marks)
  • [PYQ 2022, 2025]: Design 3-bit generator & 4-bit checker using odd parity bit. (08 to 10 Marks)