minuszerodegrees.net

8-Bit Checksum


Simply sum up the bytes to be checksummed, then of the sum, keep only the least significant 8 bits.


Very simple example

5 bytes as follows.  All values are in hexidecimal.

  5A
  88
  FE
  3C
  9A
 ===
 2B6  <--- sum

Therefore, the 8-bit checksum of the subject 5 bytes is the 8 least significant bits of 2B6, which is B6.

( BTW.  The 4-bit checksum of the subject 5 bytes is the 4 least significant bits of 2B6, which is 6.  )
( BTW.  The 16-bit checksum of the subject 5 bytes is the 16 least significant bits of 2B6, which is 2B6, but that would normally be written as 02B6 [i.e.  showing 16 bits].  )


Calculation by software

I never calculate 8-bit checksums myself; I get software to do it.  Hex editing software usually have functionality in them to calculate checksums, and other types of hashes.  For example, in the software that I use in Windows 10, which is HxD Hex Editor, I select [Analysis] on the menubar, then choose [Checksums].  That allows me to see the result of lots of different hashing algorithms.


Scope of bytes to be checksummed

Beware.
The bytes to be checksummed are not always all of the bytes.
For example, in some BIOS expansion ROM's, the 'ROM size' byte indicates that only some of the ROM's bytes are to be checksummed.


Adjustment to get an 8-bit checksum of 00

Sometimes, you may see a reference to adjusting code/data to achieve an 8-bit checksum of 00.

A very simple example follows.  Five bytes of code/data.  It is known that the fourth and fifth bytes are not used by the code/data author.

  5F
  B0
  94
  00   <--- the fourth byte is known to be unused by the code/data author
  00   <--- the fifth byte is known to be unused by the code/data author
 ===
 1A3   <--- sum

The 8-bit checksum of the subject 5 bytes is A3 (the least significant 8 bits of 1A3).

In this example, what we do is adjust either the fourth or fifth byte (i.e. an unused byte) so that the 8-bit checksum becomes 00.
So, if we change the fifth byte from 00 to 5D, the sum of the five bytes becomes 200, and therefore, the 8-bit checksum becomes 00.

  5F
  B0
  94
  00
  5D
 ===
 200   <--- sum