EXERCISE - 1 Write a Program in C/ C++ for error detecting code using CRC-CCITT (16 bit) Objective: To enable the receiver of a message transmitted through noisy channel to check whether the message has been corrupted. The aim of an error detection technique is to enable the receiver of a message transmitted through noisy channel to determine whether the message has been corrupted. To do this, the transmitter constructs a value called a checksum that is the function of message and appends it’s to message. The receiver can then use the same function to calculate the checksum of the received message and compare it with the appended checksum to see if the message was correctly received.

IMPLEMENTATION

Figure: Euclidean division algorithm The message is represented by a information polynomial i(x). i(x) is store as a bit pattern of k length in an integer array. The k information bits are represented by k-1 degree polynomial i(x) = i(k-1)x(k-1) + i(k-2)x(k-2) +……………………………..+i1x+i0 A polynomial code is specified by its generating polynomial g(x). If we assume that we are dealing with a code in which codewords have n bits of which k are information bits and n-k are check bits . The generator polynomial for such a code has degree n-k and has the form g(x) = x(n-k) + g(n-k-1)x(n-k-1) +……………………….+g1x+1 The generator polynomial chosen is CCITT-16 (x16+x12+x5+1). 1

CS601: Computer Networks lab

Encoding Procedure At Sender Steps 1) Multiply i(x) by x(n-k) by putting zeros in n-k low order positions 2) Divide x(n-k)i(x) by g(x) to get r(x). Use Euclidean division algorithm with a feedback shift register as shown in above figure x(n-k)i(x) = g(x) q(x) + r(x) where q(x) is quotient and r(x) is remainder 3) Add remainder r(x) to x(n-k)i(x) by putting check bits in n-k lower order positions 4) Based on randomness, the message can be transmitted with error or without error. 5) For transmission with error, introduce an error at random position to the message x(n-k)i(x) and display the position of the error. 6) Transmitted codeword is b(x) = x(n-k)i(x) + r(x) Decoding Procedure at the Receiver Steps 1) The received message b(x) is divided by g(x) using Euclidean division algorithm 2) If the remainder is 0 then there is no error in the transmission else Error in the transmission.

2

CS601: Computer Networks lab

EXERCISE - 2 Write a Program in C/ C++ for hamming code generation for error detection/correction Objective: To Detect and Correct Single bit errors using Hamming Code. Hamming Code is used to detect and correct single bit error. The key to Hamming Code is the use of extra parity bits. Hamming code consists of k information bits and n-k check bits, where n is the total number of bits in the codeword. Parity bits are placed in positions having power of 2. IMPLEMENTATION (7,4) HAMMING CODE: The Hamming Code for 4-bits of data uses 3 redundant bits. Hamming Code for 4 data bits d4 is d4 b7 d3 b6 d2 b5 r3 b4 d1 b3 r2 b2 r1 b1...(position of bits in code) d3 d2 d1

where r1 r2 and r3 are redundant bits. PROCEDURE FOR DETERMINING REDUNDANT BITS: The ability of detecting and correcting errors of Hamming Code comes with the cost of redundant bits. These 3-bits are used to take care of all the 8 different possible states of transmitted 7-bits. The r-bits are determined using following equations: d1 = r1 + r2 | d2 = r1 + r3 | modulo-2 arithmetic d3 = r2 + r3 | d4 = r1 + r2 + r3 |

3

CS601: Computer Networks lab

These equations are further solved to calculate r-bits: r1 = d1 + d2 + d4 r2 = d1 + d3 + d4 r3 = d2 + d3 + d4

PROCEDURE FOR ERROR DETECTION AND CORRECTION: On the receiver side 3 position bits(p1-p3) are calculated: p1 = r1 + d1 + d2 + d4 p2 = r2 + d1 + d3 + d4 p3 = r3 + d2 + d3 + d4

These values indicate one of the eight possible states of received code: --------------------------------------------------------p3 p2 p1 state Action for correction...