0% found this document useful (0 votes)
4 views

Error correction

program for error correction code

Uploaded by

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

Error correction

program for error correction code

Uploaded by

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

Ex. No.

: 8
SIMULATION OF ERROR CORRECTION CODES (LIKE CRC)
Date :

AIM
To write a java program to implement Cycle Redundancy Check.

PROCEDURE:
1. Import the necessary java packages.
2. Get the generator and data from the user using buffered reader and store it as string data type.
3. Append (generator-1) number of zero (0’s) of the end of the message.
4. Perform the polynomial division operation (X-OR) using the given divisor.
5. Repeat the step 2 until we get a (generator-1) remainder.
6. Append (generator-1) CRC bits at the end of original message and send it to receiver.
7. Perform the polynomial division operation for the received message using the given divisor
and check whether it return 0, if true the message received without error, otherwise message
received with error.

PROGRAM:
import java.io.*;
class crc
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Generator : ");
String gen = br.readLine();
System.out.print("Enter Data : ");
String data = br.readLine();
String code = data;
while(code.length() < (data.length() + gen.length() - 1))
code = code + "0";
code = data + div(code,gen);
System.out.println("The transmitted Code Word is : " + code);
System.out.print("Please enter the received Code Word : ");
String rec = br.readLine();
if(Integer.parseInt(div(rec,gen)) == 0)
System.out.println("The received code word contains no errors.");
else
System.out.println("The received code word contains errors.");
}
static String div(String num1,String num2)
{
int pointer = num2.length();
String result = num1.substring(0, pointer);
String remainder = "";
for(int i = 0; i < num2.length(); i++)
{
if(result.charAt(i) == num2.charAt(i))
remainder += "0";
else
remainder += "1";
}
while(pointer < num1.length())
{
if(remainder.charAt(0) == '0')
{
remainder = remainder.substring(1, remainder.length());
remainder = remainder + String.valueOf(num1.charAt(pointer));
pointer++;
}
result = remainder; remainder = "";
for(int i = 0; i < num2.length(); i++)
{
if(result.charAt(i) == num2.charAt(i))
remainder += "0";
else
remainder += "1";
}
}
return remainder.substring(1,remainder.length());
}
}
OUTPUT:

RESULT:
Thus, the java program for Cyclic Redundancy Check was successfully implemented.

You might also like