Ex - No 10
Ex - No 10
Algorithm:
Step 7: If the remainder is zero there is no error otherwise there is some error in the received
bits
import java.util.Scanner;
class CRC{
for(int i=0;i<datastream.length();i++)
data[i] = Integer.parseInt(datastream.charAt(i)+"");
for(int i=0;i<generator.length();i++)
divisor[i] = Integer.parseInt(generator.charAt(i)+"");
//Calculation of CRC
for(int i=0;i<datastream.length();i++){
if(data[i]==1)
for(int j=0;j<divisor.length;j++)
data[i+j] ^= divisor[j];
//Display CRC
for(int i=0;i<datastream.length();i++)
data[i] = Integer.parseInt(datastream.charAt(i)+"");
datastream = sc.nextLine();
generator = sc.nextLine();
for(int i=0;i<datastream.length();i++)
data[i] = Integer.parseInt(datastream.charAt(i)+"");
for(int i=0;i<generator.length();i++)
divisor[i] = Integer.parseInt(generator.charAt(i)+"");
//Calculation of remainder
for(int i=0;i<datastream.length();i++){
if(data[i]==1)
for(int j=0;j<divisor.length;j++)
data[i+j] ^= divisor[j];
for(int i=0;i<data.length;i++)
if(data[i]==1){
valid = false;
break;
//https://darshangajara.com/2013/10/30/crc-java/
//https://www.tutorialspoint.com/what-is-algorithm-for-computing-the-crc
Output:
/*Output
Enter data stream: 101010
Enter generator: 11111
The CRC code is: 1010101010
Enter CRC code: 1010100010
Enter generator: 11111
Data stream is invalid. CRC error occurred.
*/
Result:
Thus the java program to simulate the behavior of Error Correction Code is executed
successfully.