Search code examples
mathhexbytebit-manipulationchecksum

My checksum of 5 bytes of data does not


I'm processing 6-byte messages from a piece of serial hardware. In their manual, the manufacturer has laid out that the checksum of each message (its 6th byte) is composed of 'the low byte of the summation of the rest of the message.'

Here is one of their examples, dissected

Here are some others

I haven't tried all those examples yet, let me show my work on the first 'dissected' example:

This is the formula as provided:

Low byte of 0xB2 + 0x00 + 0x69 + 0x1A + 0x83 = 0x68

So, the summation is 0x1B8, if I take the first 8-bits, I get 0xB8 Hmmm... am I doing that wrong?

I thought for a bit and guessed, oh, maybe they just do a bitwise-operation instead, that's pretty common on older hardware right? So I wrote out the bits of each part and XORed the series together...

  • 0xB2 ^ 0x00 = 0xB2 (duh)
  • 0xB2 ^ 0x69 = 0xDB
  • 0xDB ^ 0x1A = 0xC1
  • 0xC1 ^ 0x83 = 0x42

I did this by hand, and by calculator. Same result.

I was able to reproduce my computations in my program, my checksums are pretty different than what the hardware is outputting. The manual model number matches the hardware I have...

Looking at the binary of each part of the summation, I'm not sure I can see a clear pattern to each their documented output. In some checksums, like the IPv4 header, the carry is shifted or added back into the checksum, could that be the case here?

My question is:

Am I making a math error in how this checksum is being calculated?

Any help would be greatly appreciated! Thank you.


Solution

  • I just attacked all the samples with the Windows RT calculator, and all of the others (here) are fine - it's just the first example (which you dissected) that is erroneous. This looks like a simple documentation typo.