Of course not 2 times. And if you send it 2 times and they are not correct then you so what? You send it anoter 2 times?

One widely used in memories error correction is the Hamming error correction.

A n-bit byte will be injected with k bits. The number k depends on the number of bits. The injected bits will cover the power of 2 positions in the byte. For an 8-bit byte for example, there will be 4 injected bits, in positions 1,2,4 and 8.

Example:

suppose we have the byte 11000100. It is an 8-bit byte thus 4 bits will be injected. We name them P1 P2 P4 and P8. The final byte will be 12bits length:

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

**P1** | **P2** | 1 | **P4** | 1 | 0 | 0 | **P8** | 0 | 1 | 0 | 0 |

To calculate the injected bits we use the XOR for the following bits of the 12-bit byte:

P1= XOR of bits [3,5,7,9,11]

P2= XOR of bits [3,6,7,10,11]

P4= XOR of bits [5,6,7,12]

P8= XOR of bits [9,10,11,12]

Our previous byte will become:

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

**0** | **0** | 1 | **1** | 1 | 0 | 0 | **1** | 0 | 1 | 0 | 0 |

**Checking the byte:**To check the byte received, you do:

C1=XOR of bits [1,3,5,7,9,11]

C2=XOR of bits [2,3,6,7,10,11]

C3=XOR of bits [4,5,6,7,12]

C4=XOR of bits [8,9,10,11,12]

And this will produce a 4-bit number: C=C

_{8}C

_{4}C

_{2}C

_{1}If c==0, no error occured.

But if C!==0, then the number C will determine which bit is fault.

Example:

C=0000 ; No error

C=0001 ; 1st bit is wrong

C=0101 ; 5th bit is wrong

Then you correct this bit by xoring it and the byte is ok.

The above code will check for a single error. What if there is error in 2 bits? Then you need another bit injection, the P13. This will increase the size of 1 more bit. the P13 will be:

P13= XOR of all 12 bits.

To check the data received, you use the same C number as before in conjuction with P13 as follows:

If C==0 and P13==0 : No error

If C!==0 and P==1: Single error that can be fixed

if C!==0 and P==0 : Double error that can be found but not fixed.

if C==0 and P13==1 : Error in P13

Hope this will meet your demands.