CS 325: CS Hardware and Software Organization and Architecture Error Detection and Correction
Error Detection and Correction Bits are occasionally flipped in transmission. For example: 1101001 is sent, but 0101011 is received. Adding redundancy can allow us to detect, and possibly correct, some errors of this type.
Error Detection and Correction Simple approach: Repeat each bit Repeat each bit twice. For bit a, transmit aa. If the receiver gets two different bits, it requests a retransmission. This is an error detecting code. Allows for one error to be detected, but is not error correcting since retransmission is necessary Repeat each bit three times. For each bit a, transmit aaa. Now the receiver can correct a single error. Why?
Problem with the simple approach The receiver can detect and correct bit errors if each bit is transmitted three times. How does this affect performance? Bus bandwidth efficiency = 33% Better approach Parity check codes Has the ability to detect odd number of bit flips using a single parity bit.
Calculating bit string parity A bit string has odd parity if the number of 1s in the string is odd. 100011, 1, 000010 have odd parity A bit string has even parity if the number if 1s in the string is even. 01100, 000, 11001001 have even parity Assume 0 is an even number
Parity check code Assume we are transmitting blocks of k bits. A block (w) of length (k) is encoded as (wa), where the value of the parity bit (a) is chosen so that (wa) has even parity. Example: If w = 10110, we send wa = 101101, which has even parity With no bit flips in the transmission, the receiver gets the bit string exactly as it was sent by the sender. Bit string has even parity. If there are an odd number of bit flips in the transmission, the receiver gets a bit string with odd parity. Retransmission is requested. If there are an even number of bit flips in the transmission, the receiver gets a bit string with even parity. The error(s) go undetected. Ex: 011101 Another solution?
2D parity check code Blocks of bits are organized in rows and columns m x n matrix The parity bit of each row is calculated, and appended to the row before it is transmitted. The parity of each column is calculated, and appended to the column before it is transmitted. The parity bit of the entire matrix is computed.
2D parity check Example (even parity): Original data: 1100, 1011, 0111, 0101 MN + M + N + 1 bits transferred. 4*4 + 4 + 4 + 1 = 25 bits 16/25 64% bus bandwidth efficiency Row Parity 1 Column Parity Matrix Parity bit
2D parity check code Data bits: mn Parity bits: m + n + 1 Total # of bits sent: mn + m + n + 1 Efficiency becomes greater as block size increases Ex: 2x2 block 2*2 + 2 + 2 + 1 = 9, 4/9 bits are data: 44% efficient Ex: 6x6 block 6*6 + 6 + 6 + 1 = 49, 36/49 bits are data: 73.5% efficient Ex: 10x10 block 10 * 10 + 10 + 10 + 1= 121, 100/121 bits are data: 82.6% efficient Problem with large block size: Higher probability of errors transmitted due to smaller number of parity bits/data bit
2D parity check Another Example (even parity): Original data: 1100, 1011, 0111, 0101 Row Parity 1 Column Parity Matrix Parity bit
2D parity check Another Example (even parity): Original data: 1100, 1011, 0111, 0101 Row Parity 1 Column Parity Matrix Parity bit
2D parity check Another Example (even parity): Received data: 1100, 1011, 0111, 0111 Row Parity 1 Column Parity Matrix Parity bit
2D parity check Another Example (even parity): Received data: 1100, 1011, 0111, 0111 Possible to fix the problem without retransmitting the data Row Parity 1 Column Parity Matrix Parity bit
2D parity check Another Example (even parity): Received data: 1100, 1011, 0111, 0111 Possible to fix the problem without retransmitting the data Row Parity 1 Column Parity Matrix Parity bit
2D parity check 2D parity check can detect and correct all 1 bit errors. Error bit 1
2D parity check 2D parity check can detect all 2 bit errors. Can’t correct all 2 bit errors. Data must be resent. Error bits 1
2D parity check 2D parity check can detect all 3 bit errors. Can’t correct all 3 bit errors. Data must be resent. Error bits 1
2D parity check 2D parity check can detect most 4 bit errors. Can’t correct all 4 bit errors. Data must be resent. Example of a 4 bit error that is NOT detected: Error bits 1
Non-ECC vs. ECC RAM Non-Error-Correcting Code Memory Can’t detect errors Most standard DDR SDRAM is Non-ECC Memory Cheaper, but susceptible to errors Error-Correcting Code (ECC) Memory Used where data corruption can’t be tolerated Most RAM used by servers and high end computers are ECC RAM More expensive than Non-ECC memory
Hamming Code Error detecting/correcting codes invented by Richard Hamming in 1950. Solution for error-prone punched card readers at Bell Labs Still used today Can correct 1 bit errors Can detect up to 2 bit errors
Hamming Code – Parity bits Hamming code works by placing parity bits throughout a bit string of size (w) (p) parity bits creates a bit string of size 2m – 1, of which 2m – m – 1 bits can be used for data. Common Hamming code sizes: Hamming(3,1), 2 parity bits, 33% efficiency Hamming(7,4), 3 parity bits, 57% efficiency Hamming(15,11), 4 parity bits, 73% efficiency Hamming(31,26), 5 parity bits, 84% efficiency Read as Hamming(total bits, data bits)
Hamming Code Example: Using Hamming(7,4), create the Hamming codeword for the following 4 bit string: 0101 Hamming(7,4) 7 total bits 4 data bits 3 parity bits Parity bits are always located in the codeword at positions of 2n. P1 = 20 = 1 P2 = 21 = 2 P3 = 22 = 4
Hamming Code Example: Using Hamming(7,4), create the Hamming codeword for the following 4 bit string: 0101 1 2 3 4 5 6 7 P1 P2 P3
Hamming Code Example: Using Hamming(7,4), create the Hamming codeword for the following 4 bit string: 0101 Now, calculate the parity bits 1 2 3 4 5 6 7 P1 P2 P3
Hamming Code To calculate P1: find parity of substring(1,3,5,7) 1 2 3 4 5 6 7 P1 P2 P3 To calculate P1: find parity of substring(1,3,5,7)
Hamming Code To calculate P1: find parity of substring(1,3,5,7) 2 3 4 5 6 7 P1 P2 P3 To calculate P1: find parity of substring(1,3,5,7) 20 = 1, so check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, … P1 0 1 1 = 0
Hamming Code To calculate P1: find parity of substring(1,3,5,7) 2 3 4 5 6 7 P1 P2 P3 To calculate P1: find parity of substring(1,3,5,7) 20 = 1, so check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, … P1 0 1 1 = 0 To calculate P2: find the parity of substring(2,3,6,7)
Hamming Code To calculate P1: find parity of substring(1,3,5,7) 2 3 4 5 6 7 P1 P2 P3 To calculate P1: find parity of substring(1,3,5,7) 20 = 1, so check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, … P1 0 1 1 = 0 To calculate P2: find the parity of substring(2,3,6,7) 21 = 2, so check 2 bits, skip 2 bits, check 2 bits, skip 2 bits, … P2 0 0 1 = 1
Hamming Code To calculate P1: find parity of substring(1,3,5,7) 2 3 4 5 6 7 P1 P2 P3 To calculate P1: find parity of substring(1,3,5,7) 20 = 1, so check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, … P1 0 1 1 = 0 To calculate P2: find the parity of substring(2,3,6,7) 21 = 2, so check 2 bits, skip 2 bits, check 2 bits, skip 2 bits, … P2 0 0 1 = 1 To calculate P3: find the parity of substring(4,5,6,7)
Hamming Code To calculate P1: find parity of substring(1,3,5,7) 2 3 4 5 6 7 P1 P2 P3 To calculate P1: find parity of substring(1,3,5,7) 20 = 1, so check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, … P1 0 1 1 = 0 To calculate P2: find the parity of substring(2,3,6,7) 21 = 2, so check 2 bits, skip 2 bits, check 2 bits, skip 2 bits, … P2 0 0 1 = 1 To calculate P3: find the parity of substring(4,5,6,7) 22 = 4, so check 4 bits, skip 4 bits, check 4 bits, skip 4 bits, … P3 1 0 1 = 0
Hamming Code To calculate P1: find parity of substring(1,3,5,7) 2 3 4 5 6 7 P1 P2 P3 To calculate P1: find parity of substring(1,3,5,7) 20 = 1, so check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, … P1 0 1 1 = 0 To calculate P2: find the parity of substring(2,3,6,7) 21 = 2, so check 2 bits, skip 2 bits, check 2 bits, skip 2 bits, … P2 0 0 1 = 1 To calculate P3: find the parity of substring(4,5,6,7) 22 = 4, so check 4 bits, skip 4 bits, check 4 bits, skip 4 bits, … P3 1 0 1 = 0 Now we know P1, P2, and P3 and can calculate the codeword: 0 1 0 0 1 0 1
Hamming Code Another Example: Using Hamming(15,11), create the Hamming codeword for the following 11 bit string: 00110110010 Hamming(15,11) 15 total bits 11 data bits 4 parity bits Parity bits are always located in the codeword at positions of 2n. P1 = 20 = 1 P2 = 21 = 2 P3 = 22 = 4 P4 = 23 = 8
Hamming Code Example: Using Hamming(15, 11), create the Hamming codeword for the following 11 bit string: 00110110010 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 P1 P2 P3 P4
Hamming Code Example: Using Hamming(15, 11), create the Hamming codeword for the following 11 bit string: 00110110010 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 P1 P2 P3 P4
Hamming Code Codeword: 010101110110010 To calculate P1: find parity of substring(1,3,5,7,9,11,13,15) P1 0 0 1 0 1 0 0 = 0 To calculate P2: find parity of substring(2,3,6,7,10,11,14,15) P2 0 1 1 1 1 1 0 = 1 To calculate P3: find parity of substring(4,5,6,7,12,13,14,15) P3 0 1 1 0 0 1 0 = 1 To calculate P4: find parity of substring(8,9,10,11,12,13,14,15) P4 0 1 1 0 0 1 0 = 1 Codeword: 010101110110010 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 P1 P2 P3 P4
Hamming Code Try: Using Hamming(7,4), create the Hamming codeword for the following 4 bit string: 1100 P1 1 1 0 = 0 P2 1 0 0 = 1 P3 1 0 0 = 1 1 2 3 4 5 6 7 P1 P2 P3 1 2 3 4 5 6 7
Checking Hamming Code for Correctness Example: Using Hamming(7,4), check the Hamming codeword for correctness. 1 2 3 4 5 6 7
Checking Hamming Code for Correctness Example: Using Hamming(7,4), check the Hamming codeword for correctness. P1 1 1 0 = 0 P2 1 0 0 = 1 P3 1 0 0 = 1 1 2 3 4 5 6 7
Checking Hamming Code for Correctness Example: Using Hamming(15,11), check the Hamming codeword for correctness. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Checking Hamming Code for Correctness Example: Using Hamming(15,11), check the Hamming codeword for correctness. P1 0 0 1 0 1 0 1 = 1 P2 0 1 1 0 1 0 1 = 0 P3 0 1 1 1 0 0 1 = 0 P4 0 0 1 1 0 0 1 = 1 How to find flipped bit? Just add wrong parity bit offsets: 2 + 4 + 8 = 14 Flip bit at position 14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Checking Hamming Code for Correctness Example: Using Hamming(15,11), check the Hamming codeword for correctness. P1 0 0 1 0 1 0 1 = 1 P2 0 1 1 0 1 0 1 = 0 P3 0 1 1 1 0 0 1 = 0 P4 0 0 1 1 0 0 1 = 1 How to find flipped bit? Just add wrong parity bit offsets: 2 + 4 + 8 = 14 Flip bit at position 14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Checking Hamming Code for Correctness Example: Using Hamming(15,11), check the Hamming codeword for correctness. P1 0 0 1 0 1 0 1 = 1 P2 0 1 1 0 1 0 1 = 0 P3 0 1 1 1 0 0 1 = 0 P4 0 0 1 1 0 0 1 = 1 How to find flipped bit? Just add wrong parity bit offsets: 2 + 4 + 8 = 14 Flip bit at position 14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 P1 0 0 1 0 1 0 1 = 1 P2 0 1 1 0 1 1 1 = 1 P3 0 1 1 1 0 1 1 = 1 P4 0 0 1 1 0 1 1 = 0
Checking Hamming Code for Correctness Example: Using Hamming(15,11), check the Hamming codeword for correctness. State whether or not the codeword is correct. If the codeword is not correct, determine the mistake (flipped- bit) and generate the correct codeword Turn in your work for this problem before leaving class Name at the top Graded as a quiz 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15