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

Import Public Class Public Static Int Public Static Void New New

This Java program implements a cyclic redundancy check (CRC) to detect errors in transmitted data. It takes in a data word from the user, generates a CRC code by dividing the data word with a fixed generator polynomial, appends the CRC to the data word and transmits the frame. Upon receiving the frame, it divides the received data with the generator polynomial and checks if the remainder is all zeros to determine if there are any errors.

Uploaded by

zeal originals
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Import Public Class Public Static Int Public Static Void New New

This Java program implements a cyclic redundancy check (CRC) to detect errors in transmitted data. It takes in a data word from the user, generates a CRC code by dividing the data word with a fixed generator polynomial, appends the CRC to the data word and transmits the frame. Upon receiving the frame, it divides the received data with the generator polynomial and checks if the remainder is all zeros to determine if there are any errors.

Uploaded by

zeal originals
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

Scanner;
public class CRC
{
public static int n;
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
CRC crc = new CRC();
String copy,rec,code,zero="0000000000000000";
System.out.println("enter the dataword to be sent");
code = sc.nextLine();
n = code.length();
copy=code;
code+=zero;
code = crc.divide(code);
System.out.println("dataword = "+copy);
copy=copy.substring(0,n)+code.substring(n);
System.out.print("CRC = ");
System.out.println(code.substring(n));
System.out.println("transmitted frame is = "+copy);
System.out.println("enter recived data:");
rec=sc.nextLine();
if(zero.equals(crc.divide(rec).substring(n)))
System.out.println("correct bits recived");
else
System.out.println("recived frame contains one or more
errors");
sc.close();
}
public String divide(String S)
{
String div="10001000000100001";
int i,j;
char x;
for(i=0;i<n;i++)
{
x=S.charAt(i);
for(j=0;j<17;j++)
{
if(x=='1')
{
if(S.charAt(i+j)!=div.charAt(j))

S=S.substring(0,i+j)+"1"+S.substring(i+j+1);
else

S=S.substring(0,i+j)+"0"+S.substring(i+j+1);

}
}
}
return S;
}
}

You might also like