Opinions on 16-bit checksums.
From: Kermit (Kermit333_at_hotmail.com)
Date: 08/25/04
- Next message: Joe: "Re: Newbie - Pic, Stamp, Eprom"
- Previous message: TEMP: "Newbie - Pic, Stamp, Eprom"
- Next in thread: jamie: "Re: Opinions on 16-bit checksums."
- Reply: jamie: "Re: Opinions on 16-bit checksums."
- Reply: Jack Klein: "Re: Opinions on 16-bit checksums."
- Reply: Hans-Bernhard Broeker: "Re: Opinions on 16-bit checksums."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 24 Aug 2004 22:17:49 GMT
Hello all,
Since I see that Endianess is a current topic, I'd like to ask a question
concerning it and calculating 16-bit checksums. I've never seen a standard
anywhere that describes exactly what a checksum is.
However, I have mainly seen them calculated in one of three ways.
1) Simply calculate a 32-bit value which is the sum of each byte added to a
running sum. At the end, cast this 32-bit value to a 16-bit value, and call
it the checksum.
2) Calculate the same way as above, but pull two bytes of the file out at a
time such that you are adding them as 16-bit values in one of the following
ways.
a) Little-endian
b) Big-endian.
For example, lets say I have a 6-byte file consisting of:
0x00 0x01 0x02 0x03 0x04 0x05
Algorithm 1 would yield:
0x00 + 0x01 + 0x02 + 0x03 + 0x04 + 0x05 = 0x000f
Algorithm 2-a would yield:
0x0100 + 0x0302 + 0x0504 = 0x0906
Algorithm 2-b would yield:
0x0001 + 0x0203 + 0x0405 = 0x0609
I've always preferred to calculate it 16-bits at a time, because that way,
you can detect byte-reversal issues. And, apparently, I've always calculated
them assuming a little endian format. However, I recently ran into a problem
with a distributor trying to program a big-endian file into a flash part.
They switched the bytes, then ignored it, which is their fault, but my
problem. But, since it was the first time I'd ever worked with a big-endian
binary file, I guess it threw me and I wanted to double check my thinking.
How does everyone else on the list calculate a 16-bit checksum.
--kermit
-- It wasn't easy being Greazy ....but it was interesting.
- Next message: Joe: "Re: Newbie - Pic, Stamp, Eprom"
- Previous message: TEMP: "Newbie - Pic, Stamp, Eprom"
- Next in thread: jamie: "Re: Opinions on 16-bit checksums."
- Reply: jamie: "Re: Opinions on 16-bit checksums."
- Reply: Jack Klein: "Re: Opinions on 16-bit checksums."
- Reply: Hans-Bernhard Broeker: "Re: Opinions on 16-bit checksums."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|