0% found this document useful (0 votes)
0 views2 pages

Develop A Program For Error Detecting Code Using CRC-CCITT (16-Bits)

The document presents a Java program that implements error detection using the CRC-CCITT (16-bits) algorithm. It allows users to input data and a divisor, computes the CRC code, and checks for errors in the received CRC code. The program utilizes bitwise operations to perform polynomial division and determine if there are any errors in the transmitted data.

Uploaded by

kavichengappa
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)
0 views2 pages

Develop A Program For Error Detecting Code Using CRC-CCITT (16-Bits)

The document presents a Java program that implements error detection using the CRC-CCITT (16-bits) algorithm. It allows users to input data and a divisor, computes the CRC code, and checks for errors in the received CRC code. The program utilizes bitwise operations to perform polynomial division and determine if there are any errors in the transmitted data.

Uploaded by

kavichengappa
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/ 2

3.

Develop a program for error detecting code using CRC-CCITT (16-


bits).

package error_detecting;
import java.util.Arrays;
import java.util.Scanner;
public class crc {
static int[] input(String x) {

Scanner s = new Scanner(System.in);


System.out.println("Enter no. of " + x + " bits:");
int size = s.nextInt();
int arr[] = new int[size];
System.out.println("Enter " + x + " bits:");
for (int i = 0; i < size; i++)
arr[i] = s.nextInt();
return arr;
}

public static void main(String[] args) {


int[] data, divisor;
int tot_length, i;
Scanner s = new Scanner(System.in);
data = input("data");
divisor = input("divisor");
tot_length = data.length + (divisor.length - 1);
int crc[] = new int[tot_length];
int dividend[] = Arrays.copyOf(data, tot_length);
int reminder[] = Arrays.copyOf(dividend, tot_length);
reminder = divide(divisor, reminder);
for (i = 0; i < dividend.length; i++)
crc[i] = (dividend[i] ^ reminder[i]);
System.out.println("CRC Code: " + Arrays.toString(crc));
System.out.println("Enter CRC code of " + (tot_length) + "bits.");
for (i = 0; i < crc.length; i++) {
reminder[i] = s.nextInt();
}
reminder = divide(divisor, reminder);
System.out.println(Arrays.binarySearch(reminder, 1) > 0 ? "Error" :
"NoError");

System.out.println("FINISHED");
}

static int[] divide(int divisor[], int reminder[]) {

int cur = 0;
while (true) {
for (int i = 0; i < divisor.length; i++)
reminder[cur + i] = (reminder[cur + i] ^ divisor[i]);
while (reminder[cur] == 0 && cur != reminder.length - 1)
cur++;
if ((reminder.length - cur) < divisor.length)
break;
}
return reminder;
}
}

You might also like