(Mis)using CRCs for error correction
Cyclic Redundancy Check codes are commonly used for detecting errors, but they can also be used to correct single and multibit errors. To be able to correct e errors per code word and detect code words with d errors, its needed for the minimum hamming distance of a code to be > 2e+d
So what is the relation between the code word length and the minimum hamming distances for crc codes?
generator polyom | hd≥3 | hd≥4 | hd≥5 | hd≥6 | hd≥7 | hd≥8 | |
---|---|---|---|---|---|---|---|
CRC- 4 | 0xF0000000 | 5 | 5 | 5 | 5 | 5 | 5 |
CRC- 5 | 0x28000000 | 31 | 4 | 4 | 4 | 4 | 4 |
CRC- 7 | 0xA2000000 | 15 | 15 | 7 | 7 | 7 | 7 |
CRC- 7 | 0x12000000 | 127 | 6 | 6 | 6 | 6 | 6 |
CRC- 7 | 0x6E000000 | 63 | 63 | 9 | 9 | 7 | 7 |
CRC- 8 | 0x07000000 | 127 | 127 | 8 | 8 | 8 | 8 |
CRC- 8 | 0x39000000 | 17 | 17 | 17 | 7 | 7 | 7 |
CRC- 8 | 0xD5000000 | 93 | 93 | 10 | 10 | 8 | 8 |
CRC-12 | 0x80F00000 | 2047 | 2047 | 13 | 13 | 12 | 12 |
CRC-12 | 0x80B00000 | 510 | 171 | 36 | 13 | 13 | 13 |
CRC-12 | 0x1F100000 | 65 | 65 | 65 | 21 | 13 | 11 |
CRC-15 | 0x8B320000 | 127 | 127 | 127 | 127 | 22 | 22 |
CRC-16 | 0x10210000 | 32767 | 32767 | 16 | 16 | 16 | 16 |
CRC-16 | 0x80050000 | 32767 | 32767 | 16 | 16 | 16 | 16 |
CRC-16 | 0xA0970000 | 32766 | 32766 | 83 | 83 | 24 | 24 |
CRC-16 | 0xC5030000 | 7161 | 496 | 85 | 36 | 24 | 22 |
CRC-16 | 0x90D90000 | 151 | 151 | 151 | 151 | 21 | 21 |
CRC-24 | 0x80510100 | 7161 | 7161 | 1030 | 1030 | 24 | 24 |
CRC-32 | 0x04C11DB7 | 4294967295 | 91638 | 3006 | 299 | 203 | 122 |
CRC-32 | 0x404098E2 | 1024 | 1023 | 1023 | 1023 | 1023 | 1023 |
CRC-32 | 0x1EDC6F41 | 2147483647 | 2147483647 | 5275 | 5275 | 209 | 209 |
CRC-32 | 0x741B8CD7 | 114695 | 114695 | 16392 | 16392 | 184 | 184 |
CRC-32 | 0xF4ACFB13 | 65534 | 65534 | 32768 | 32768 | 306 | 306 |
CRC-32 | 0x32583499 | 65538 | 65538 | 32770 | 32770 | 166 | 166 |
CRC-32 | 0x20044009 | 65538 | 65538 | 32770 | 32770 | 32 | 32 |
CRC-32 | 0xA833982B | 65537 | 65537 | 65537 | 1091 | 113 | 89 |
CRC-32 | 0x00210801 | 65537 | 65537 | 65537 | 31 | 31 | 31 |
These where found using crc_test.c
Actually correcting errors is pretty trivial, for a single bit error, feeding the code below with the calculated crc XOR the received crc, will give you the distance from the end where the error ocured, and yeah if they match (crc=0) thn theres no single bit error
int get_single_error(int crc, int len){ int i, v=1; for(i=0; i<len ; i++){ if(v == crc) return i; v= (v<<1) ^ (generator_polynom & (v>>31)); } return -1; }
ill post some code examples to fix multibit errors later …