Dear All,
I have a string which I need to get the checksum values via java. I need to get CRC 16 Modbus. Any help on how to achieve this? So below is what I found but is for CRC32. Thank you.
import java.util.zip.CRC32;
import java.util.zip.Checksum;
public class chksum
{
public static void main(String args[]){
String str = "Generate CRC32 Checksum For Byte Array Example";
//Convert string to bytes
byte bytes[] = str.getBytes();
Checksum checksum = new CRC32();
/* * To compute the CRC32 checksum for byte array, use * * void update(bytes[] b, int start, int length) * method of CRC32 class. */
checksum.update(bytes,0,bytes.length);
/* * Get the generated checksum using * getValue method of CRC32 class. */
long lngChecksum = checksum.getValue();
System.out.println("CRC32 checksum for byte array is :" + lngChecksum);
}
}