Computer Architecture and Assembly Language Practical Session 10
Error detection and correction data transmission via communication channels channel noise errors may happen we need techniques that enable reliable delivery of digital data over unreliable communication channels general idea: add some redundancy (extra data) to a message this extra data is used to check consistency of the delivered message to recover data determined to be corrupted
Hamming Distance Hamming distance (d) between two code words of equal length is an amount of 1-bit changes required to reach from one word to the other (number of 1’s in the XOR between the words) 000 011 d(000, 011) = 2 10101 11110 d(10101, 11110) = 3 Minimum Hamming distance is the smallest Hamming distance between all possible pairs in a set of words. Example: Given the following coding scheme, let’s find the minimum Hamming distance. 00000 01011 10101 11110 d(00000,01011)=3 d(00000,10101)=3 d(00000,11110)=4 d(01011,10101)=4 d(01011,11110)=3 d(10101,11110)=3 d=3
Minimum Hamming Distance d can detect d-1 errors Example: 00000 01011 10101 11110 3 errors can take us from one legal code word to another can detect at least 3-1=2 errors d=3 01011 00000 01000 01010 01011 Minimum Hamming Distance d can fix d-1 erasures 3 erasures can take us from one legal code word to another can detect at least 3-1=2 erasures 01011 00000 0_000 0_0_0 0_0__ Minimum Hamming Distance d can fix errors 2 errors can take us from two different legal code words to the same illegal word 00000 01000 01010 can fix at least floor((3-1)/2)=1 error 11110 01110
Answer: yes. We need a hamming distance d=3 to fix 1 error. Given four data words, can we use 5-bit code words for fixing 1 error? Answer: yes. We need a hamming distance d=3 to fix 1 error. 00000 11100 10111 01011 d(00000,11100)=3 d(11100, 10111)=3 d(00000,10111)=4 d(11100, 01011)=4 d(00000,01011)=3 d(10111, 01011)=3 We can create code words with independent graphs of a single error code words. 00000 00001 00010 00100 01000 10000 11100 11000 10100 01100 11110 11101 10111 10110 10101 10011 11111 00111 01011 01010 01001 01111 00011 11011
Parity Check Given a data word, a code word is created by adding a parity bit to the end of the data word d=2 (why?) Can detect 1 error and fix 1 erasure Code word Data word 00000 0000 00011 0001 00101 0010 00110 0011 0001 1 send: 0011 1 00_1 1 receive: 1 error occurs erased bit is a parity of other bits: parity (0011) = 1
Hamming Code (4,3) We assume that there may be at most one error. if p0 is wrong, we get p2 p1 p0 =√√x = 001b = 1 p0 should be at index 1 if p1 is wrong, we get p1 p1 p0 =√x√ = 010b = 2 p1 should be at index 2 if p2 is wrong, we get p2 p1 p0 =x√√ = 100b = 4 p2 should be at index 4 if x0 is wrong, we get p2 p1 p0 =√xx = 011b = 3 x0 should be at index 3 … if x3 is wrong, we get p2 p1 p0 =xxx = 111b = 7 x3 should be at index 7 We assume that there may be at most one error. indexes: 7 6 5 4 3 2 1 code word: 4 data bits: x0 x1 x2 x3 3 parity bits: p0 p1 p2 We calculate: why we interleave bits of data and parity in this way ? Example: We got 0100111 Sender sent 0000111 p0 = 1 = x3 ⊕x1 ⊕x0 = 0 ⊕ 0 ⊕ 1 = 1 √ p1 = 1 = x3 ⊕x2 ⊕x0 = 0 ⊕ 1 ⊕ 1 = 0 x p2 = 0 = x3 ⊕x2 ⊕x1 = 0 ⊕ 1 ⊕ 0 = 1 x p2 p1 p0 =xx√ = 110b = 6 The error bit is at index 6 (from right to left) in the code word error bit is x2
Cyclic Redundancy Check CRC is an error-detecting code Given a data, its non trivial (cryptographic) challenge to find another data with the same CRC code. CRC can protect data (even from deliberate damage) Explanation is needed
Binary Pattern as Polynomial
CRC Polynomials (common) CRC-8-ATM x8 + x2 + x + 1 CRC-16-IBM x16 + x15 + x2 + 1 CRC-16-CCITT x16 + x12 + x5 + 1 CRC-32-IEEE 802.3 x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 which one is used when?
Sending – Calculation Steps Generator is chosen sequence of bits, of which the first and last are 1 CRC check sequence is computed by long-division of message by generator check sequence has 1 fewer bits than generator Check sequence is appended to the original message
Sending – Calculation Steps Compute 8-bit CRC a message ‘W’ (0x57). Select Generator: CRC-8-ATM x8 + x2 + x + 1 = 100000111 ‘W’ is 01010111= x6 + x4 + x2 + x + 1 Extend ‘W’ with 8 bits: 0101011100000000 Perform XOR of the word get in step (3) by generator CRC code is the remainder Append CRC code to ‘W’
Generating CRC Code long-division of message by generator 0101011100000000 100000111 Each time apply XOR on the extended message, when place a generator from the left-most ‘1’ bit of the extended message xor 100000111 001011011000000 xor 100000111 0011010110000 xor 100000111 01010101100 xor 100000111 0010100010 Stop when CRC code has 1 fewer bits than generator CRC Code: 10100010
Receiving – Calculation Steps Append CRC code to the message: 0101011110100010 Perform long division by the generator If the reminder is not 0: an error occurred 0101011110100010 100000111 xor only a single error occurred? why? 100000111 There is no errors in received message. result: 00000000