You are on page 1of 4

Hamming Code

Error Correcting Code Hamming Codes are used in detecting and correcting a code. An error-correcting code is an algorithm for expressing a sequence of numbers such that any errors which are introduced can be detected and corrected (within certain limitations) based on the remaining numbers. Errors can happen in a variety of ways. Bits can be added, deleted, or flipped. Errors can happen in fixed or variable codes. Error-correcting codes are used in CD players, high speed modems, and cellular phones. Error detection is much simpler than error correction. For example, one or more "check" digits are commonly embedded in credit card numbers in order to detect mistakes. The example below shows how to detect and correct an error in a code. Rules 1. Must send the original data (Di) and the check bits (Cj ). 2. Number the positions in binary starting at one, and position the check bits (Cj ) at the power of two. 3. Calculated the check bits by taking the exclusive-or of all the data bits whose address contains one in the same place as the check bit

Address Code

0 0 1 C0

0 1 0 C1

0 1 1 D1

1 0 0 C2

1 0 1 D2

1 1 0 D3

1 1 1 D4

C0 = D1 xor D2 xor D4 C1 = D1 xor D3 xor D4 C2 = D2 xor D3 xor D4

Example
You are given three different codes 101, 110 and 001 figures out the check bits for the codes.

Code 101 Address Code D1 = 1 D2 = 0 D3 = 1 Address Code 0 0 1 C0 0 1 0 C1 0 1 1 1 1 0 0 C2 1 0 1 0 1 1 0 1 0 0 1 C0 0 1 0 C1 0 1 1 D1 1 0 0 C2 1 0 1 D2 1 1 0 D3

C0 = 1 xor 0 = 1 C1 = 1 xor 1 = 0 C2 = 0 xor 1 = 1 Address Code 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 1

__________________________________________ Code 110 D1 = 1 D2 = 1 D3 = 0 0 0 1 C0 0 1 0 C1 0 1 1 1 1 0 0 C2 1 0 1 1 1 1 0 0

Address Code

C0 = 1 xor 1 = 0 C1 = 1 xor 0 = 1 C2 = 1 xor 0 = 1

Address Code

0 0 1 0

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 0

1 1 0 1

______________________________________________ Code 100 D1 = 1 D2 = 0 D3 = 0 0 0 1 C0 0 1 0 C1 0 1 1 1 1 0 0 C2 1 0 1 0 1 1 0 0

Address Code

C0 = 1 xor 0 = 1 C1 = 1 xor 0 = 1 C2 = 0 xor 0 = 0 Address Code 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 1

Now, assume an error happens at the first code 110 that the bit in position 5 is toggled. Find it by getting its address. correct code is 101101 after being toggled 101111

Address Code

0 0 1 1

0 1 0 0

0 1 1 1

1 0 0 1

1 0 1 1

1 1 0 1

A0 = C0 xor D1 xor D2 = 1 xor 1 xor 1 = 1 A1 = C1 xor D1 xor D3 = 0 xor 1 xor 1 = 0 A2 = C3 xor D2 xor D3 = 1 xor 1 xor 1 = 1 A2 A1 A0 = 101 = 5 where the error happen.

You might also like