Hamming’s Error-Correcting Code (ECC) can correct single-bit errors in transmitted data.
The basic idea is to add extra bits (parity bits) to the original data in such a way that the resulting code can detect and correct errors.
Let’s use Hamming(7,4) code as an example, which adds 3 parity bits to a 4-bit data word, resulting in a 7-bit codeword. The positions of these parity bits are chosen to cover certain combinations of data bits.
Steps to Append Hamming’s ECC:
- Original Data (4 bits): 1001
- Calculate Parity Bits: The parity bits are usually calculated based on the positions of the data bits. In Hamming(7,4) code, the positions of the parity bits are powers of 2 (1, 2, 4). Let’s denote the original data bits as D1, D2, D3, D4 (left to right).
- Parity bit P1 covers D1, D2, D4.
- Parity bit P2 covers D1, D3, D4.
- Parity bit P4 covers D2, D3, D4. To calculate each parity bit, we count the number of 1s in the positions it covers and set the parity bit to 1 if the count is odd, and 0 otherwise. For example:
- P1 = D1 ⊕ D2 ⊕ D4 = 1 ⊕ 0 ⊕ 1 = 0 (Even parity)
- P2 = D1 ⊕ D3 ⊕ D4 = 1 ⊕ 0 ⊕ 1 = 0 (Even parity)
- P4 = D2 ⊕ D3 ⊕ D4 = 0 ⊕ 0 ⊕ 1 = 1 (Odd parity)
- Append Parity Bits to Data: The parity bits are inserted at their respective positions in the codeword. So, the resulting 7-bit codeword is: 0111001
Transmission and Error Detection/Correction:
Now, let’s assume that during transmission, one bit is flipped. The received data becomes 1101001.
- Check Parity Bits: The receiver recalculates the parity bits based on the received data.
- P1′ = D1′ ⊕ D2′ ⊕ D4′ = 1 ⊕ 1 ⊕ 1 = 1 (Odd parity)
- P2′ = D1′ ⊕ D3′ ⊕ D4′ = 1 ⊕ 0 ⊕ 1 = 0 (Even parity)
- P4′ = D2′ ⊕ D3′ ⊕ D4′ = 0 ⊕ 0 ⊕ 1 = 1 (Odd parity)
- Identify the Error: By comparing the calculated parity bits with the received parity bits, the receiver can identify the position of the error. In this case, the error occurs in position 1 (P1), as the calculated parity bit P1′ is different from the received parity bit.
- Correct the Error: The receiver corrects the error by flipping the bit in the detected position. So, the corrected data becomes: 1001
Thus, using Hamming’s Error-Correcting Code, the receiver can identify and correct the error that occurred during transmission.