You are on page 1of 4

HAMMING CODE

• It is an error detection and correction techniques.


• Given by R. W. Hamming
• 7 bit Hamming code is used commonly.
• In 7 bit Hamming code, there are 4 data bits and 3 parity bits.
• Parity bit position is calculated using the formula,
2n { where n = 0.1.2…….n} i.e.
20 = 1, 21 = 2, 22 = 4
and the remaining positions are for data bits:
D7 D6 D5 P4 D3 P2 P1

7 6 5 4 3 2 1
• P1 ------> D3 D5 D7
• P2------> D3 D6 D7
• P4------> D5 D6 D7
Cont..

• Example 1: A 4 bit data 1011 is to be transmitted from sender to the receiver


using a 7 bit even parity hamming code. Obtain the hamming code for the
above data?
• Solution:
D7 D6 D5 P4 D3 P2 P1
1 0 1 1
Now, calculate the value of P1, P2, P3 as:
• P1 ------> D3 D5 D7 = 111, so to make even parity the value of P1 = 1
• P2------> D3 D6 D7 = 101, so to make even parity the value of P2 = 0
• P4------> D5 D6 D7 = 101, so to make even parity the value of P4 = 0

• Therefore, the final Hamming code will be:


• D7 D6 D5 P4 D3 P2 P1

1 0 1 0 1 0 1
Cont..

• Ex 2: If the 7 bit Hamming code word received by a receiver is 1011011.


Assuming the even parity, state whether the received code word is correct or not?
If not, locate the bit having error.
• Solution:
D7 D6 D5 P4 D3 P2 P1

1 0 1 1 0 1 1
• checking for P4: D5D6D7 = 101 and P4 value is 1, here total number of 1’s is
odd but it is even parity, so it means here is an error. Whenever this situation
comes put the parity bit as 1. So, P4 = 1.
• Checking for P2: D3D6D7 = 001, P2 = 1, here total number of 1’s is even so no
error. As, there is no error, so P2 = 0.
• Checking for P1: D3D5D7 = 011, P1 = 1, here total number of 1’s is odd, so
error, therefore, P1= 1.
Cont..

• Now P4P2P1 = (101)2 = (5)10 which means that fifth bit contains an error.
• D7 D6 D5 P4 D3 P2 P1
1 0 1 1 0 1 1
Bit No: 7 6 5 4 3 2 1

• So, the correct codeword is:



• D7 D6 D5 P4 D3 P2 P1

1 0 0 1 0 1 1

You might also like