Cyclic Redundancy Check Program in C
In this program, you will know Cyclic Redundancy Check and get an example code of Cyclic Redundancy Check Program in C programming.
CRC full form
CRC stands for Cyclic Redundancy Check. It is a kind of checksum algorithm used to detect errors in data transferred over a communications channel or stored on a data storage media.
What is Cyclic Redundancy Check
A Cyclic Redundancy Check (CRC) is a type of error-detecting method. It is used to identify data corruption.
CRC works by calculating a checksum (a value based on the quantity of bits in a message) and comparing it to a previously calculated checksum. If the two values do not match, the message is corrupted.
CRC in computer networks are commonly used in digital communications, and storage devices.
How to crc error detection and correction program
1. Calculate CRC or checksum for the given data.
2. Compare the Calculated CRC or checksum with the existing one.
3. If the two values differ, the message is invalid.
4. To correct the error, compare the two values to identify the corrupted bit.
5. Flip the corrupted bit to make it correct in the message.
6. Recalculate the CRC or checksum and compare with the existing one.
7. If the calculated and the existing CRC or checksum match, the message is successfully corrected.
Cyclic Redundancy Check example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <stdio.h> int main() { int i,j,n=8; int crc[n]; int message[n] = {1,0,1,0,1,1,1,1}; // message of 8-bit int generator[n] = {1,0,1,1,0,0,1,1}; //generator of 8-bit for (i=0; i<n; i++) { crc[i] = message[i]; } // calculating division for (i = 0; i < n; i++) { j = 0; do { if (crc[j]>=generator[0]) { for (int k = j; k < 4; k++) { if (crc[k]==generator[k-j]) { crc[k] = 0; } else { crc[k] = 1; } } } j++; } while (j < 4); } // print result printf("\n\nCRC is = "); for (i = 0; i < n; i++) { printf("%d",crc[i]); } printf("\n"); return 0; } |
Output :