Computer Architecture and Assembly Language Practical Session 10
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 ( redundancy extra data) to a message extra data • 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 10101 11110 d(000, 011) = 2 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 00000 01010 01011 Minimum Hamming Distance d can fix d-1 erasures 3 erasures can take us from one legal code word to another 00000 0_0_0 Minimum Hamming Distance d can fix 2 errors can take us from two different legal code words to the same illegal word can fix at least floor((3 -1)/2)=1 error 00000 can detect at least 3 -1=2 erasures 0_0__ errors 01000 01010 11110 01011
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(00000, 10111)=4 d(00000, 01011)=3 d(11100, 10111)=3 d(11100, 01011)=4 d(10111, 01011)=3 We can create code words with independent graphs of a single error code words 0000 1 1000 0 00010 00000 10110 11000 0001 0 0010 0 11101 10100 10101 00111 110111 11100 11110 01010 01100 11111 01001 01011 10011 01111
Parity Check • Given a data word, a code word is created by adding a parity bit to the end of the data word parity bit • d=2 (why? ) • Can detect 1 error and fix 1 erasure Can detect 1 error and fix 1 Data word Code word 00000 00011 00101 00110 send: 0001 1 receive: 0011 1 1 error occurs 00_1 1 erased bit is a parity of other bits: parity (0001) = 1
Hamming Code (4, 3) We assume that there may be at most one error. 7 indexes: 6 5 4 3 2 if p 1 is wrong, we get p 1 p 0 =√x√ = 010 b = 2 p 1 should be at index 2 1 code word: 4 data bits: x 0 x 1 x 2 x 3 if p 2 is wrong, we get p 2 p 1 p 0 =x√√ = 100 b = 4 p 2 should be at index 4 3 parity bits: p 0 p 1 p 2 We calculate: why we interleave bits of data and parity in this way ? • • • if x 0 is wrong, we get p 2 p 1 p 0 =√xx = 011 b = 3 x 0 should be at index 3 … if x 3 is wrong, we get p 2 p 1 p 0 =xxx = 111 b = 7 x 3 should be at index 7 Example: We got 0100111 if p 0 is wrong, we get p 2 p 1 p 0 =√√x = 001 b = 1 p 0 should be at index 1 Sender sent 0000111 p 0 = 1 = x 3 ⊕x 1 ⊕x 0 = 0 ⊕ 1 = 1 √ p 1 = x 3 ⊕x 2 ⊕x 0 = 0 ⊕ 1 = 0 x p 2 = 0 = x 3 ⊕x 2 ⊕x 1 = 0 ⊕ 1 ⊕ 0 = 1 x p 2 p 1 p 0 =xx√ = 110 b = 6 The error bit is at index 6 (from right to left) in the code word error bit is x 2
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)
Binary Pattern as Polynomial
CRC Polynomials (common) CRC-8 -ATM x 8 + x 2 + x + 1 CRC-16 -IBM x 16 + x 15 + x 2 + 1 CRC-16 -CCITT x 16 + x 12 + x 5 + 1 CRC-32 -IEEE 802. 3 x 32 + x 26 + x 23 + x 22 + x 16 + x 12 + x 11 + x 10 + x 8 + x 7 + x 5 + x 4 + x 2 + x + 1
Sending – Calculation Steps 1. Generator is chosen – sequence of bits, of which the first and last are 1 2. CRC check sequence is computed by long. CRC check sequence is computed division of message by generator – check sequence has 1 fewer bits than generator 3. Check sequence is appended to the original message
Sending – Calculation Steps Compute 8 -bit CRC a message ‘W’ (0 x 57). 1. Select Generator: CRC-8 -ATM 1. x 8 + x 2 + x + 1 = 100000111 2. ‘W’ is 01010111= x 6 + x 4 + x 2 + x + 1 3. Extend ‘W’ with 8 bits: 010101110000 4. Perform XOR of the word get in step (3) by generator – CRC code is the remainder 5. Append CRC code to ‘W’
Generating CRC Code long-division of message by generator 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 xor Stop when CRC code has 1 fewer bits than generator 0101011100000111 00110101100000111 0101100 100000111 0010100010 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 0 0101011110100010 100000111 xor 100000111 result: 0000 There is no errors in received message.
- Slides: 14