Data Link Layer

Hamming Code

In Bit parity we can only detect errors in data or message. we cannot rectify the data or message but in case of hamming code we can check and rectify the error. 

Hamming code is error detection and correction Technique in computer network developed by Richard w Hamming.

 

In this code we use number of parity Bits for generating Code.

Suppose our data is of length N then we use K bits for generating hamming Code of N + K bits length.

 

Steps generate code according to the following to the steps:

1) We number (N+K) from1.

2) The position of the bits are power of 2.it means 0  = 1,  21 = 2 and so on.

Each Parity bit assigned a number of bits to check their parity. this allotment of Bit must go through all the parity bit, who’s sum is M. suppose Mth bit is past through.

P1, P2, – – – – Pr then some of P1 + P2 + P3 + PR = M.

 

Now let us understand the working of Hamming code with the suitable example,

suppose we are sending the following bits.

 

Hamming Code

Data suppose we are sending a for bit data that is 1101.

 

Step 1:  finding value of k that

        N = 4  as 22 = 4 (number of Data Bit)

       X = x + 1 that is 2 + 1 = 3  (number of Parity Bit)

         Therefore parity bit equals to 3

Step 2:

      Actual code+ parity bit = N + K
      (4 bit of data + 3 bit of parity bit = 7 bit)

Step 3:

      Before making the hamming code we have to decide about the parity whether it is even or odd if even parity the number of 1’s including the parity bit will be even, and if is Odd then the number of 1’s will be Odd including the parity bit.

 

Step 4:
Place these parity bit on the   2n, (power of 2 ) that is 0  = 1,  21 = 2   position will be Parity bit position and so on.

 

 

 

 

Note:

Here for example parity bit P1 will check the bits from 1 leaving 1 bit in between.

P2 will check Bit form continuous 2 bit  leaving continuous 2 Bit in between. 

P3 will check Bit continuous 3 bit leaving continuous 3bit in between. 

P4  will check Bit continuous 4 onward leaving continuous 4 bit in between.

 

Detecting Errors:

 

Step 1:

analyzing bit 1,3,5,7

 we have  P1 = D3,D5,D7            

(P1 means 1 bit read 1 bit leave so position 1,3,5,7 Leaving 1 bit )

 

Hamming Code

P1 = 1

D3=0

D5=1

D7=1

Total bit = odd Hence Error 

as the bit parity was even.

 

So put P1=1

Untitled Diagram 72

(P2 means 2 bit read 2 bit leave so position 2,3,6,7 Leaving2 bit )

 

P2 = 1

D3=0

D6=0

D7=1

Total bit = Even Hence No Error 

as the bit parity was even.

p4

(P4 means 4 bit read 4 bit leave so position 4,5,6,7 Leaving 4 bit )

 

P4 = 1

D5=1

D6=0

D7=1

Total bit = Odd Hence Error 

as the bit parity was even.

Error Correction

Untitled Diagram 75

we put the Parity bit in format 

as P1 is odd so 1

P2 is even so we put 0

P4 is odd so we put 1

 

 

The decimal value of it is 5

Show the position 5 has error

 

Untitled Diagram 76

in last we simply inverted the 5th position into 1 –> 0

 

Know we Recheck :

P1=D3,D5,D7

(1=0,0,1) Which is even no error,

 

P2=D3,D6,D7

(1=0,01)which is even hence no error.

 

P4=D5,D6,D7

(1=0,0,1) which is even hence no Error.