A checksum is a value or byte of data that insures the integrity of data
transmitted from one electronic device to another. While learning how to
develop an application for a GPS receiver, I learned how to use checksums
in my program.
The specific checksum format the GPS receiver used was one known as
modulo 256
. The basic idea is that a stream of data is given
to a device begining and ending with an escape sequence specific to the
protocol of communications. The last byte of REAL data is the checksum.
The checksum is the DIFFERENCE between the SUM of the data and the protocols
modulus. Here is an example of Modulo 256:
Data Steam:
26 17 31 43 07 73 51 08
The checksum is the last number in the data stream
or 08 in the above example. Here is how it is computed:
26 17 31 43 07 73 51 = 248
256 - 248 = 08
256 was the modulus because we are using Modulo 256. 248 was the sum of the
data stream (except the checksum). 08 (checksum) is the difference between
256 (modulus) and 248 (sum). Given any other number, the machine returns a
NAK which instructs the transmitting device to re-transmit the data.
The unsuccessful transmission of the data can be due to many factors such
as a bad connection, frequency interference, data collision, etc.
Checksums are used in CRC (cyclic redundancy check) checks also. Imagine
a file that has a CRC verification number; this number would be calculated
by finding the difference between the CRC modulus and the sum of the data
in the file.