### Error correcting codes: Hamming Code

- Hamming code is given by RW Hamming
- It is one of the most common error correcting codes used in Random Access Memory (RAM).

### How does Hamming Code work?

- Suppose there is a message of n bits.
- We add k number of parity bits to the message.
- This changes the size of the message from n bits to n+k bits.
- The bit positions are numbered in sequence from 1 to (n+k).

**for example** if message length (n) is = 8, and number of parity bits (k) = 4 than total number of bits in hamming code will be (n+k) = (8+4) = 12bits

1 2 3 4 5 6 7 8 9 10 11 12

- Those positions numbered as a power of 2 are reserved for the parity bits and the remaining bits are data bits. See below, the bits marked as red are reserved for parity bits.

1 2 3 4 5 6 7 8 9 10 11 12

### How to calculate the number of parity bits (k)?

The number of parity bits can be calculated by the following relationship

\( 2^k – 1 \ge n + k \)if the length of a message is 8 i.e. n = 8 then the value of k can be 4 or greater than 4.