Richard,
Wow!
That is so clean and easy.
(I do have a tendency of making things complicated.)
Thank you very much!
Jay Zebryk
Southbridge, Massachusetts
Richard,
Wow!
That is so clean and easy.
(I do have a tendency of making things complicated.)
Thank you very much!
Jay Zebryk
Southbridge, Massachusetts
This information may not pertain to your current goal since you are trying to decode an existing checksum method being used by your transmitter.
However, for a simple tried and true method of byte level checksums on a datastream, the Intel Hex8 checksum method works well and is very simple.
I use this method in many projects with good success.
The Intel Hex8 file (I8HEX) checksum is the 2s compliment of the sum of the payload bytes.
The beauty of using the 2s compliment of the sum of the payload bytes is that the validation check is simple.
To validate the payload at the receiving end, the receiver sums the received payload bytes including the received checksum byte.
The result should equal zero (0).
This works because of the use of unsigned byte variables and the rollover from 255 to 0 for overflows.
In this context a number plus the 2s compliment of itself will equal zero (0) as a 2s compliment of a number behaves like the negative of the original number.
Computing the 2s compliment of a byte can be done by first computing the 1s compliment of the number, then adding one to the result.
1scomp = (number ^ $FF) This computes the 1s compliment
2scomp = 1scomp + 1
For example:
number = 73
1scomp = (73 ^ $ff) = 182
2scomp = 182 + 1 = 183
To validate just add the number to its 2s compliment.
73 + 183 = 0
This checksum method can be used for just about any length of payload bytes.
Regards,
TABSoft
Bookmarks