This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes I/O and Streams and the fly likes Generating a Checksum Value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Generating a Checksum Value" Watch "Generating a Checksum Value" New topic
Author

Generating a Checksum Value

Brendan Crisler
Greenhorn

Joined: Feb 07, 2007
Posts: 19
I'm trying to create a 100 byte ASCII string to send over a com port. Byte 99 in the string needs to be an 8-bit checksum. How do I set this byte? I've seen the java.util.zip package, but I'm not sure if that's just used for 'reading' a checksum or not. Any help is appreciated.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18753
    
  40

These days the term checksum doesn't have a meaning, in terms of an actual definition. In the past, it just means the sum of the values of all the bytes in the packet, ignoring overflows. These days, it just means a way to check -- and doesn't really imply that you are taking a sum.

It could be just a sum. It could be a CRC, of which there are tons of formulas. It could be a message digest -- MD5, SHA1, etc. It could be nearly anything. Now, admittedly, many that I listed are not 8-bit, so it may not be those.

Regardless, you need to look up, the actually definition of checksum -- used in your application, as it will be nearly impossible to guess what this thing you are communicating with, is expecting.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
Don't get me started about those stupid light bulbs.
 
subject: Generating a Checksum Value