Javatpoint Logo
Javatpoint Logo

CRC Program in Java

CRC stands for Cyclic Redundancy Check. It was invented by W. Wesley Peterson in 1961. It is an error detecting technique through which we can detect the error in digital networks(or communication channel or digital data) and storage devices. It is used to trace the accidental changes in the digital data. In this section, we will learn how to calculate and perform CRC through a Java program. Let's understand CRC in detail.

CRC Mechanism

It is an error detection mechanism in which a special number is added to the block of data. The primary goal to add the number is to identify the changes during the transmission or storage. It is calculated twice, once at the sender side during the data transmission and recalculated at the receiver side. It compares data bit by bit with originally transmitted values. If any error (corrupted bit) occurs during the transmission of data, the CRC does not match with the originally transmitted value. We can easily understand the CRC mechanism by the following figure.

CRC Program in Java
CRC Program in Java

For example, a single corrupted bit in the data results in a one-bit change in the calculated CRC, but multiple corrupted bits may cancel each other out. If multiple bits are corrupted or changed is known as a burst error.

There is some other error detection mechanism like Vertical Redundancy Check (VRC)and Longitudinal Redundancy Check (LRC), but CRC is more powerful in comparison with others. The algorithm of CRC is more complex because it uses binary division to calculate CRC. The divisor is generated using polynomials. So, CRC is also called polynomial code checksum.

Following are the steps used in CRC for error detection:

  • In the first step, we append N 0's to the data unit. The value of N is always less than the number of bits in the data unit(referred to as division which is N+1).
  • In the next step, we use the process of binary division for dividing the newly extended data by a divisor, and the reminder which we get from this division is referred to as CRC remainder.
  • In the next step, we replace all the 0's which we append before in the data unit with the remainder bits. After that, we sent the newly generated data unit to the receiver.
  • The receiver receives the data unit with the CRC remainder. After that, the receiver divides the data unit by the divisor.
  • If the remainder is zero after dividing the data unit with the divisor, unit data is not corrupted and can be accepted.
  • If the remainder is not equal to zero after dividing the data unit with the divisor, unit data is corrupted and will be discarded.

Let's take an example and understand how CRC works:

Suppose the original data is 11100 and the divisor is 1001.

  • First, we will add the zeros in the data unit part. The length of the divisor is 4, and we know that the length of the string 0s is always one less from its divisor. So, we append three zeros in the data unit, i.e., 11100.
  • After appending the zeros, the resultant string will be 11100000, which we divide by the divisor, i.e., 1001. We use the binary division process for dividing data unit by divisor.
  • The remainder which we get after dividing the data unit by the divisor is referred to as CRC remainder.
  • CRC remainder replaces the appended string of 0s at the end of the data unit, and the final string would be 11100111, which is sent across the network.


CRC Program in Java
CRC Program in Java
CRC Program in Java

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA