Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
What is algorithm for computing the CRC?
Cyclic Redundancy Check (CRC) is a block code that was invented by W. Wesley Peterson in 1961. It is commonly used to detect accidental changes to data transmitted via telecommunications networks and storage devices.
CRC involves binary division of the data bits being sent by a predetermined divisor agreed upon by the communicating system. The divisor is generated using polynomials. So, CRC is also called polynomial code checksum.
Before sending the message over network channels, the sender encodes the message using CRC. The receiver decodes the incoming message to detect error. If the message is error-free, then it is accepted, otherwise, the receiver asks for re-transmission of the message.
Algorithm for CRC Computation
When messages are encoded using CRC (polynomial code), a fixed polynomial called generator polynomial G(x) is used. The value of G(x) is mutually agreed upon by the sending and the receiving parties. A k-bit word is represented by a polynomial which ranges from x0 to xk-1. The order of this polynomial is the power of the highest coefficient, i.e. (k-1).
The length of G(x) should be less than the length of the message it encodes. Also, both its MSB (most significant bit) and LSB (least significant bit) should be 1. In the process of encoding, CRC bits are appended to the message so that the resultant frame is divisible by G(x).
Encoding Algorithm
-
The communicating parties agree upon the size of message M(x) and the generator polynomial G(x).
-
If
ris the order of G(x), thenrzero bits are appended to the low order end of M(x). This makes the block sizexrM(x). -
The block
xrM(x)is divided by G(x) using modulo-2 division (XOR operation). -
The remainder after division is added to
xrM(x)using modulo-2 addition. The result is the frame to be transmitted, T(x). This encoding procedure makes T(x) exactly divisible by G(x).
Decoding Algorithm
-
The receiver divides the incoming data frame T(x) by G(x) using modulo-2 division. Mathematically, if E(x) is the error, then modulo-2 division of [T(x) + E(x)] by G(x) is performed.
-
If there is no remainder, then it implies that E(x) = 0. The data frame is error-free and accepted.
-
A non-zero remainder indicates presence of an error E(x). The data frame is rejected and the receiver may send a negative acknowledgment back to the sender requesting retransmission.
Example of CRC Calculation
Consider a 4-bit message 1101 and generator polynomial 1011 (representing x3 + x + 1):
Step 1: Append 3 zeros to message: 1101000
Step 2: Perform modulo-2 division:
1101000 รท 1011 = quotient with remainder 010
Step 3: Append remainder to original message: 1101010
The transmitted frame is 1101010. At the receiver, dividing this by 1011 should yield zero remainder if no errors occurred.
Conclusion
CRC provides an efficient error detection mechanism using polynomial arithmetic and modulo-2 division. The algorithm ensures that transmission errors can be detected by comparing the remainder of the division operation at both sender and receiver sides.
