0% found this document useful (0 votes)
21 views6 pages

Ex - No 10

lab manual

Uploaded by

rmsnekaas786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views6 pages

Ex - No 10

lab manual

Uploaded by

rmsnekaas786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Ex.

No:10 Simulation of an error correction code (like CRC)

Aim: To simulate the behaviour of Error Correction Code in java

Algorithm:

Step 1: Get the input in the form of bits.

Step 2: Append zeros as redundancy bits.

Step 3: Divide the appended data using a divisor polynomial.

Step 4: The resulting data should be transmitted to the receiver.

Step 5: At the receiver the received data is entered.

Step 6: The same process is repeated at the receiver.

Step 7: If the remainder is zero there is no error otherwise there is some error in the received
bits

Step 8: Run the program.


Program:

import java.util.Scanner;

class CRC{

public static void main(String args[]){

Scanner sc = new Scanner(System.in);

//Input Data Stream

System.out.print("Enter data stream: ");

String datastream = sc.nextLine();

System.out.print("Enter generator: ");

String generator = sc.nextLine();

int data[] = new int[datastream.length() + generator.length() - 1];

int divisor[] = new int[generator.length()];

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

System.out.print("The CRC code is: ");

for(int i=0;i<datastream.length();i++)

data[i] = Integer.parseInt(datastream.charAt(i)+"");

for(int i=0;i<data.length;i++) System.out.print(data[i]);


System.out.println();

//Check for input CRC code

System.out.print("Enter CRC code: ");

datastream = sc.nextLine();

System.out.print("Enter generator: ");

generator = sc.nextLine();

data = new int[datastream.length() + generator.length() - 1];

divisor = new int[generator.length()];

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];

//Display validity of data

boolean valid = true;

for(int i=0;i<data.length;i++)

if(data[i]==1){

valid = false;

break;

if(valid==true) System.out.println("Data stream is valid");

else System.out.println("Data stream is invalid. CRC error occured.");


}

//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.

You might also like