Program To Implement Crc In Java

  



  1. First data bit is: 1 Remainder: 1010 101 The CRC code generated is: Enter the data to be sent: Enter bit number 10: 1 Enter bit number 9: 0 Enter bit number 8: 0 Enter bit number 7: 1 Enter bit number 6: 1 Enter bit number 5: 0 Enter bit number 4: 1 Enter bit number 3: 1 Enter bit number 2: 0 Enter bit number 1: 1 1.).
  2. CRC Cyclic Redundancy Check Java Program. Computer Networks CRC Cyclic Redundancy Check Java Program import java.util.Scanner.
  3. Java does not make it compulsory for programmers to always implement the graphs in the program. Java provides a lot of ready libraries that can be directly used to make use of graphs in the program. These libraries have all the graph API functionality required to make full use of the graph and its various features.

Java Training in Chennai Project Center in Chennai Java Training in Chennai projects for cse The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability.


importjava.net.*;
Socketsender;
ObjectInputStreamin;
intn,i=0,sequence=0;
public voidrun(){
BufferedReaderbr=new BufferedReader(new InputStreamReader(System.in));
sender= new Socket('localhost',2004);

out=newObjectOutputStream(sender.getOutputStream());
in=newObjectInputStream(sender.getInputStream());
System.out.println('reciver > '+str);
packet=br.readLine();
do{
if(i<n){
msg=msg.concat(packet.substring(i,i+1));
elseif(in){
}
sequence=(sequence0)?1:0;
System.out.println('datasent>'+msg);
System.out.println('waitingfor ack.....nn');
i++;
System.out.println('receiver > '+' packet recievednn');
else{
System.out.println('Timeout resending data....nn');
}
}while(i<n+1);
}catch(Exceptione){}
try{
out.close();
}
Crc
}
publicstatic void main(String args[]){
s.run();
Program To Implement Crc In Java
}
//RECEIVER PROGRAM
import java.io.*;
public class Reciever{
Socketconnection=null;
ObjectInputStreamin;
inti=0,sequence=0;
public voidrun(){
BufferedReaderbr=new BufferedReader(new InputStreamReader(System.in));
System.out.println('waitingfor connection...');
sequence=0;
out=newObjectOutputStream(connection.getOutputStream());
in=newObjectInputStream(connection.getInputStream());
do{
packet=(String)in.readObject();
if(Integer.valueOf(packet.substring(0,1))sequence){
sequence=(sequence0)?1:0;
}
{
System.out.println('nnreceiver >'+packet +' duplicate data');
if(i<3){
}
out.writeObject(String.valueOf((sequence+1)%2));
}
catch(Exceptione){}
System.out.println('Datarecived='+data);
}
finally{
in.close();
reciever.close();
catch(Exceptione){}
}
Recievers=new Reciever();
s.run();
}
}

OUTPUT:
Waiting for Connection....
Enter the data to send....
data sent>0m
receiver > packet recieved
waiting for ack.....
data sent>0n
receiver > packet recieved
waiting for ack.....
data sent>1a
receiver > packet recieved
waiting for ack.....
data sent>1e
receiver > packet recieved

waiting for connection...
receiver >0m
receiver >0n
receiver >1a duplicate data
receiver >1e
waiting for connection...


  • parameter model
  • Algorithm implementation
    • CRC-32
    • CRC-32/MPEG-2
    • Table generation algorithm
  • reference material
  • Source code of this article

CRC (cyclic redundancy check): is the most commonly used error checking code in the field of data communication. Its characteristic is that the length of information field and check field can be arbitrarily selected. Cyclic redundancy check (CRC) is a kind of data transmission error detection function. It calculates the polynomial of data and attaches the result to the frame. The receiving equipment also implements similar algorithm to ensure the correctness and integrity of data transmission.

CRC algorithm parameter model explanation:

  • NAME: parameter model name.
  • WIDTH: width, that is, the number of CRC bits.
  • POLY: abbreviation of the generated item, expressed in hexadecimal. For example, CRC-32 is 0x04c11db7, ignoring the highest “1”, that is, the complete generated item is 0x104c11db7.
  • INIT: This is the initialization preset value of the register (CRC) at the beginning of the algorithm, expressed in hexadecimal.
  • REFIN: of the data to be measuredEach byteWhether to reverse bitwise, true or false.
  • REFOUT: after calculation, before XOR output,The whole dataWhether to reverse bitwise, true or false.
  • XOROUT: the final CRC value is obtained after the calculated result is XOR with this parameter.

The common CRC parameter models are as follows:

CRC algorithm namePolynomial formulawidthpolynomialInitial valueResult XOR valueInput reversalOutput reversal
CRC-4/ITUx4 + x + 14030000truetrue
CRC-5/EPCx5 + x3 + 15090900falsefalse
CRC-5/ITUx5 + x4 + x2 + 15150000truetrue
CRC-5/USBx5 + x2 + 15051F1Ftruetrue
CRC-6/ITUx6 + x + 16030000truetrue
CRC-7/MMCx7 + x3 + 17090000falsefalse
CRC-8x8 + x2 + x + 18070000falsefalse
CRC-8/ITUx8 + x2 + x + 18070055falsefalse
CRC-8/ROHCx8 + x2 + x + 1807FF00truetrue
CRC-8/MAXIMx8 + x5 + x4 + 18310000truetrue
CRC-16/IBMx16 + x15 + x2 + 116800500000000truetrue
CRC-16/MAXIMx16 + x15 + x2 + 11680050000FFFFtruetrue
CRC-16/USBx16 + x15 + x2 + 1168005FFFFFFFFtruetrue
CRC-16/MODBUSx16 + x15 + x2 + 1168005FFFF0000truetrue
CRC-16/CCITTx16 + x12 + x5 + 116102100000000truetrue
CRC-16/CCITT-FALSEx16 + x12 + x5 + 1161021FFFF0000falsefalse
CRC-16/X25x16 + x12 + x5 + 1161021FFFFFFFFtruetrue
CRC-16/XMODEMx16 + x12 + x5 + 116102100000000falsefalse
CRC-16/DNPx16 + x13 + x12 + x11 + x10 + x8 + x6 + x5 + x2 + 1163D650000FFFFtruetrue
CRC-32x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 13204C11DB7FFFFFFFFFFFFFFFFtruetrue
CRC-32/MPEG-2x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 13204C11DB7FFFFFFFF00000000falsefalse

Note:The polynomial selected by CRC algorithm will affect the ability of CRC algorithm to check errorsIt is not allowed to define polynomials at will, but to choose a general CRC polynomial.

It is only given hereCRC-32CRC-32/MPEG-2The two algorithms have the same polynomial, but the parameter model is very different.
By comparing the implementation code of the two algorithms, it is easy to write other parameter model CRC algorithm with look-up table method, and then use itTable generation algorithmGenerate the corresponding table.

CRC-32

The code is as follows:

The tests are as follows:

Test results:

CRC-32/MPEG-2

The code is as follows:

The tests are as follows:

Test results:

Table generation algorithm

The tests are as follows:

Program To Implement Crc In Java

CRC online computing — ip33.com
Crc32helper -. Net source code
crc——github

Program To Implement Crc In Java Runtime

Crcdemo (Baidu disk extract code: 4xt3)