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 b5 b4 b3 b2 b1 b0 Byte 4
b7 b6 b5 b4 b3 b2 b1 b0 Byte 3
b7 b6 b5 b4 b3 b2 b1 b0 Byte 2
b7 b6 b5 b4 b3 b2 b1 b0 Byte 1
b7 b6 b5 b4 b3 b2 b1 b0 Byte 0
ECC bit5 XOR every other 32 bits
For a block of data 2n bits in length, n+1 ECC bits are needed for single-bit error correction (ECC B0 through Bn = n+1 ECC
bits). ECC bit n indicates parity of the entire array. If it is different than the stored ECC bit n, it indicates an error in the data
array. You can determine the location of the error using the lower n ECC bits (B0 to Bn-1).
To determine if an error occurred, XOR the saved and calculated ECC bits. If the result is zero, no error occurred. If the
result of the ECC XOR operation is not zero, then the location of the failing bit is given by the inverse of the ECC XOR result.
If the failing bit location is greater than or equal to the size of the data block (bit n of the inverted ECC XOR is set), then the
error is in the ECC bits. The ECC bit that is corrupt is the bit that is set as a result of the XOR of the two sets of ECC bits.
failing_bit_location = ~(ecc_saved ^ ecc_calculated)
An error in the most significant ECC bit n masquerades as an error in the most significant bit of the data. To properly detect
and correct an error in the MSB of the ECC, include an extra ECC bit (n+2 ECC bits). These two most significant ECC bits
should be identical if they are error free. If they are different, you can determine the failing ECC bit by XORing the saved and
calculated ECC bits.