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).
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 ).
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. PYQ Numerical Solution: 5211 Code Conversion [PYQ 2018]
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:
7. PYQ Master Puzzle: The 12-Bit Register Decoder [PYQ 2022]
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)
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. What is Excess-3 Code?
[concept] Concept: Excess-3 Definition Excess-3 (XS-3) is a non-weighted binary code. Each decimal digit (0 through 9) is represented by the 4-bit binary value of .
- Decimal:
- Excess-3 representation:
1.1 Differences: Standard BCD (8421) vs. Excess-3 (XS-3)
| Feature | Standard BCD (8421) | Excess-3 (XS-3) |
|---|---|---|
| Weighting | Weighted positional code (weights: ). | Non-weighted code (each representation is ). |
| Self-Complementing | No (e.g. 1’s complement of BCD 1 [0001] is 1110, which is invalid, not BCD 8). | Yes (bitwise inversion of XS-3 yields XS-3 ). |
| Zero Representation | 0000 (equal to electrical zero/disconnected state). | 0011 (prevents false line fault detection). |
| Arithmetic Carry Rule | Add 0110 () if sum or carry is generated. | Add 0011 () if carry is generated; subtract 0011 () if no carry is generated. |
| Unused States | States 1010 to 1111 () are invalid. | States 0000 to 0010 () and 1101 to 1111 () are invalid. |
Why do we use Excess-3?
- Simplified Subtraction (Self-Complementing): The primary advantage of Excess-3 is that the 1’s complement of an Excess-3 digit is the Excess-3 representation of its 9’s complement (e.g. 1’s complement of
0100[1] is1011[8]). This makes subtraction circuits in early decimal calculators incredibly simple to design. - Transmission Reliability: Unlike standard BCD where is represented by
0000(which is indistinguishable from a line disconnection or fault), the smallest valid Excess-3 code word is0011(decimal 0). This prevents signal transmission line faults from being misread as valid data.
2. Excess-3 Addition Mechanics
Because Excess-3 values always have an extra offset of built-in, adding two Excess-3 digits yields:
To restore the correct Excess-3 bias of :
- Case A: A carry is generated (Sum ) Add
0011() to correct the sum nibble. - Case B: No carry is generated (Sum ) Subtract
0011() (or add1101) to correct the sum nibble.
Step-by-Step Addition Examples:
Example 1: Excess-3 Addition with Sum (No Carry)
Add and in Excess-3:
0101 & (2 + 3 = 5) \\ +0110 & (3 + 3 = 6) \\ \hline 1011 & (\text{Raw Binary Sum} = 11_{10} \to \text{No Carry}) \\ -0011 & (\text{No Carry} \implies \text{Subtract } 3) \\ \hline \mathbf{1000} & (\text{Corrected Sum} = 8_{10} \implies 5_{\text{decimal}} \text{ in XS-3}) \end{array}$$ **Final Answer:** **$1000_{\text{XS-3}}$** (corresponds to $5_{10}$).
Example 2: Excess-3 Addition with Sum (Carry Generated)
Add and in Excess-3:
1001 & (6 + 3 = 9) \\ +1000 & (5 + 3 = 8) \\ \hline \mathbf{1} \ 0001 & (\text{Raw Binary Sum} \to \text{Carry generated!}) \\ +0011 & (\text{Carry generated} \implies \text{Add } 3 \text{ to sum nibble}) \\ \hline \mathbf{1} \ 0100 & (\text{Carry is pushed to next nibble}) \end{array}$$ Grouped into 4-bit nibbles: $\mathbf{0100\ 0100_{\text{XS-3}}}$ (corresponds to $11_{10}$ in decimal).
3. 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:
-
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:
-
Evaluating the 9’s Complement of (): The Excess-3 code word for the 9’s complement of is:
-
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 :
-
Comparing Results:
4. The Mathematics of Self-Complementing Weighted Codes
Unlike Excess-3 (which is non-weighted), many weighted 4-bit codes (like , ) are also self-complementing. There is a strict mathematical constraint on the weights of such codes.
The Self-Complementing Weight Theorem
For a weighted 4-bit binary code with weights to be self-complementing, the sum of its individual weights must equal exactly 9:
Algebraic Proof:
- Let the code representation of a decimal digit be . Its value is:
- For the code to be self-complementing, the 9’s complement () must be represented by the bitwise inverted word :
- Add the two equations together:
- Since (as one bit is always
0and the other is1):
Verification of Common Codes:
- Code: Self-complementing.
- Code: Self-complementing.
- BCD Code: Not self-complementing.
5. Complete 9’s Complement Symmetry Table
| Decimal Digit () | BCD (8421) | Excess-3 Code () | 1’s Comp of XS-3 | 9’s Comp Digit () | XS-3 Code of () |
|---|---|---|---|---|---|
| 0 | 0000 | 0011 | 1100 | 9 | 1100 |
| 1 | 0001 | 0100 | 1011 | 8 | 1011 |
| 2 | 0010 | 0101 | 1010 | 7 | 1010 |
| 3 | 0011 | 0110 | 1001 | 6 | 1001 |
| 4 | 0100 | 0111 | 1000 | 5 | 1000 |
| 5 | 0101 | 1000 | 0111 | 4 | 0111 |
| 6 | 0110 | 1001 | 0110 | 3 | 0110 |
| 7 | 0111 | 1010 | 0101 | 2 | 0101 |
| 8 | 1000 | 1011 | 0100 | 1 | 0100 |
| 9 | 1001 | 1100 | 0011 | 0 | 0011 |
5. 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: .
- Output (LSB):
- Output :
- Output :
- 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: 2.01 BCD & Weighted Digital Codes | 2.02 Excess-3 Code & Self-Complementing Logic | 2.04 Error Control, Parity Generators & Checkers
2.03 Gray Code & Code Conversions
What is Gray Code?
Gray Code (also called Reflected Binary Code) is an -bit non-weighted binary coding system. Its defining property is that only one bit changes state (from
0to1or1to0) between any two consecutive values.
1. Physical Significance: Why Use Gray Code?
Standard binary numbers are ideal for math, but they cause severe glitches when interfacing with the physical world due to simultaneous multi-bit transitions:
A. Rotary Shaft Encoders (Position Sensing)
Optical sensors read angular position from coded disks:
- The Binary Problem: Transitioning from decimal 3 (
011) to 4 (100) requires three bits to flip at once. Due to microscopic mechanical misalignments, the sensors will not trigger at the exact same instant. For a fraction of a millisecond, the processor might read an erroneous state like111(decimal 7) or010(decimal 2), leading to positioning errors. - The Gray Code Solution: Transitioning from 3 (
010in Gray) to 4 (110in Gray) flips only the MSB. The sensor is physically guaranteed to read either 3 or 4, with no intermediate erroneous states.
B. Low-Power VLSI Design
In high-speed integrated circuits, flipping bus lines charges/discharges parasitic capacitances, consuming dynamic power. By using Gray code, the average number of bit transitions (switching activity) is minimized, lowering power consumption.
2. 4-Bit Gray Code Lookup Table
Notice how the codes reflect. The second half is the mirror image of the first half (excluding the MSB).
| Decimal Value | Standard Binary | Gray Code |
|---|---|---|
| 0 | 0000 | 0000 |
| 1 | 0001 | 0001 |
| 2 | 0010 | 0011 |
| 3 | 0011 | 0010 |
| 4 | 0100 | 0110 |
| 5 | 0101 | 0111 |
| 6 | 0110 | 0101 |
| 7 | 0111 | 0100 |
| 8 | 1000 | 1100 |
| 9 | 1001 | 1101 |
| 10 | 1010 | 1111 |
| 11 | 1011 | 1110 |
| 12 | 1100 | 1010 |
| 13 | 1101 | 1011 |
| 14 | 1110 | 1001 |
| 15 | 1111 | 1000 |
3. Conversion Algorithms and Flows
Conversions between pure binary and Gray code are performed using the Exclusive-OR (XOR, ) operator.
3.1 Binary-to-Gray Conversion
Binary-to-Gray Conversion Flow:
Binary: B3 -------> B2 -------> B1 -------> B0
| | | |
| XOR XOR XOR
v v v v
Gray: G3 G2 G1 G0- The MSB of the Gray code is identical to the MSB of the binary number:
- Each subsequent Gray bit is found by XORing the corresponding binary bit with the binary bit to its left:
Binary-to-Gray Conversion: Convert Binary to Gray
Result:
3.2 Gray-to-Binary Conversion
Gray-to-Binary Conversion Flow:
Gray: G3 G2 G1 G0
| ^ ^ ^
| | | |
v XOR XOR XOR
Binary: B3 -------> B2 -------> B1 -------> B0- The MSB of the binary number is identical to the MSB of the Gray code:
- Each subsequent binary bit is found by XORing the previously calculated binary bit with the next Gray code bit:
Gray-to-Binary Conversion: Convert Gray to Binary
Result:
4. Hardware Implementation
To design a combinational circuit that converts a 4-bit Gray code input () to a 4-bit Binary output (), we map the Gray-to-Binary recurrence relations:
This maps directly to a cascade of three XOR gates:
graph LR G3[Input G3] --> B3[Output B3] G3 --> XOR1[XOR Gate 1] G2[Input G2] --> XOR1 XOR1 --> B2[Output B2] B2 --> XOR2[XOR Gate 2] G1[Input G1] --> XOR2 XOR2 --> B1[Output B1] B1 --> XOR3[XOR Gate 3] G0[Input G0] --> XOR3 XOR3 --> B0[Output B0]
Past Year Questions (PYQs)
- [PYQ 2017]: Define Reflected code. (04 Marks)
- [PYQ 2018]: Convert into Gray code. (12 Marks)
- Solution: Convert to binary: . Perform binary-to-gray:
- Gray Code:
- [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 [PYQ 2017, 2018]
Major Exam Theory Question (2017, 2018 - 4 Marks)
Question: Explain the fundamental differences between Error Detecting codes and Error Correcting codes.
| Parameter | Error Detecting Codes | Error Correcting Codes |
|---|---|---|
| Primary Function | Detects the presence of errors during transmission. | Detects the error AND automatically determines its bit location to correct it. |
| Action on Error | Flags error to receiver; requires retransmission. | Automatically corrects error without requesting retransmission. |
| Redundancy Overhead | Low overhead; requires few redundant bits {e.g., 1 parity bit}. | High overhead; requires multiple redundant check bits {e.g., Hamming distance}. |
| Implementation Complexity | Simple hardware {cascaded XOR gates}. | Complex logic {syndrome decoders & bit-flipping networks}. |
| Standard Examples | Parity 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 [PYQ 2022, 2025]
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 0 | 1 |
0 0 1 | 0 |
0 1 0 | 0 |
0 1 1 | 1 |
1 0 0 | 0 |
1 0 1 | 1 |
1 1 0 | 1 |
1 1 1 | 0 |
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 [PYQ 2018]
Limitations of Simple Parity
- Odd-Bit Error Detection Only: Parity can ONLY detect an odd number of bit errors {1, 3, 5 flipped bits}.
- 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}.
- No Correction Capability: Parity indicates that an error occurred, but cannot identify which bit flipped.
5.1 Differences: Parity Codes vs. Hamming Codes
| Feature | Simple Parity Codes | Hamming Codes (e.g., 7-bit) |
|---|---|---|
| Primary Capability | Error detection only. | Single-bit error detection AND correction. |
| Error Detection Limit | Detects only odd numbers of bit errors (). Fails on even errors. | Detects up to 2-bit errors (with SEC-DED), corrects 1-bit errors. |
| Error Correction Limit | Zero (requires retransmission). | Corrects exactly one flipped bit. |
| Bit Overhead | Minimal (exactly 1 parity bit added, regardless of data size). | Higher ( parity bits for data bits, for data bits). |
| Syndrome Decoder Complexity | Very low (cascaded XOR/XNOR gates). | Medium (decoder logic to calculate error position syndrome). |
| Typical Use Cases | Short-distance transmission, memory buses. | ECC memory, satellite communications, network packets. |
6. Master Tutorial: 7-Bit Hamming Code Error Control
To overcome the limitations of simple parity, Richard Hamming developed a method to locate and correct a single-bit error by using overlapping parity sets.
6.1 Bit Allocation Schema
A 7-bit Hamming code contains 4 data bits () and 3 redundant parity bits (). The parity bits are positioned at indices that are powers of 2.
7-Bit Codeword Positions:
1 2 3 4 5 6 7
+------+------+------+------+------+------+------+
| P1 | P2 | D3 | P4 | D5 | D6 | D7 |
+------+------+------+------+------+------+------+
2^0 2^1 Data 2^2 Data Data DataThe binary weight of each position determines which parity bits check it:
- Position 3 () is checked by (LSB=1) and (middle=1).
- Position 5 () is checked by (LSB=1) and (MSB=1).
- Position 6 () is checked by (middle=1) and (MSB=1).
- Position 7 () is checked by , , and .
6.2 Parity Generator (Transmitter End)
Assuming even parity, each parity bit is calculated by XORing the data bits in its check set:
- checks positions with LSB = 1 ():
- checks positions with middle bit = 1 ():
- checks positions with MSB = 1 ():
Worked Example: Encode Data
1100()Given data bits: .
- Calculate Parities:
- Construct Codeword:
Codeword:
- (Bit 1)
- (Bit 2)
- (Bit 3)
- (Bit 4)
- (Bit 5)
- (Bit 6)
- (Bit 7)
1100001
6.3 Parity Checker & Error Correction (Receiver End)
Upon receiving the 7-bit codeword, the receiver computes three check bits ():
The check bits form the Syndrome Word ():
- Syndrome (Decimal 0): No error occurred during transmission.
- Syndrome (Decimal ): A single-bit error occurred at bit position . To correct the error, simply invert bit .
Worked Example: Correcting a Bit Error
Suppose the received codeword is
1110001(the 3rd bit flipped from0to1during transmission).
- Extract received bits:
- .
- Calculate Check Bits:
- Evaluate Syndrome:
- Correction: Bit position 3 is incorrect. Flip Bit 3 () from
1to0. The corrected codeword is1100001, and the recovered data is1100.
7. 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)