Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Checksum crc 16 modbus

800271May 12 2011 — edited May 12 2011
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);	
	} 
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 9 2011
Added on May 12 2011
3 comments
863 views