Search code examples
hexchecksumdata-integrity

How is this hex checksum calculated?


I am currently doing some work interfacing with an embedded system. Within this system there are a series of hexadecimal configuration values, and a checksum at the end.

The four values are as follows:

  • 0A346149
  • 0A346169
  • 0A3460C4
  • 0A346189

The 'checksum' required is 047A0000

The very limited documentation I have for this suggests that the checksum is a byte addition of the four values, however I cannot replicate this.

How has this checksum been calculated, and can you work through it step-by-step?


Solution

  • It is the sum of all of the individual bytes taken one byte at a time.

    >>> (0x0A + 0x34 + 0x61 + 0x49 + 
         0x0A + 0x34 + 0x61 + 0x69 + 
         0x0A + 0x34 + 0x60 + 0xC4 + 
         0x0A + 0x34 + 0x61 + 0x89)
    1146
    >>> 0x047a
    1146
    

    (It's possible that it's just a 16-bit checksum and the 0000 bytes are not a part of it. If they are, 047A0000 is an unusual byte arrangement for 0x47a—it's neither big nor little endian.)