Calculation of CRC in Java

I am reading a file from serialport using the x-modem protocol and a 133 byte packet. I read that

1 byte is SOH 2 byte packet number 3 byte nagative of packet number next 128 bytes data 2 bytes CRC sent from other side. 

I need to calculate the CRC from 128 bytes of data and 2 bytes of crc sent on the other hand, that I have to make it a single byte, and I will have to compile with my calculated crc. How can i do this in java?

+2
source share
3 answers

Try using Jacksum .

+5
source

Sun JDK 1.6 contains sun.misc.CRC16, but it is likely that this is not the CRC16 you are looking for, because it uses several different polynomials.

+1
source

Here is my C code, which is trivial for a port for Java - you can use it in any way. Word references refer to an unsigned 16-bit value - you should be able to use char instead in Java.

For too long I have been working with 16-bit CRC, so I don’t remember if there are options based on sowing. I am sure that I used this code in the X-Modem implementation back when.

Source posted on tech.dolhub.com .

+1
source

Source: https://habr.com/ru/post/1315233/


All Articles