From: Brad Dye's Paging Information Resource Page


CHECKSUM CALCULATION PROGRAM

REM - This sample BASIC program converts the checksum value "sum" into the
REM - three characters which are sent as part of the TAP protocol. The variables
REM - d1, d2, and d3 contain the three digits which are to be added to the
REM - transmitted data block. "INT" is the integer function which returns the
REM - integer portion of a number. This function is required if the variables
REM - are floating point numbers. If they are declared as integers then the INT
REM - function is not required. This BASIC program may easily be converted to
REM - other programming languages.
REM -
sum = 379
REM - Following the checksum example in the TAP Specification Document:
REM - <STX> 1 2 3 <CR> A B C <CR> <ETX> the checksum value is 379.
REM - The following code will create the three characters to be transmitted
REM - in order to represent this checksum.
REM -
d3 = 48+sum-INT(sum/16)*16
sum = INT(sum/16)
d2 = 48+sum-INT(sum/16)*16
sum = INT(sum/16)
d1 = 48+sum-INT(sum/16)*16
REM -
REM - Print the three character checksum in decimal and ASCII
REM -
PRINT "d1="; d1, "d2="; d2, "d3="; d3
PRINT "d1$="; CHR$(d1), "d2$="; CHR$(d2), "d3$="; CHR$(d3)


MORE CHECKSUM HELP

The following is a message from: Dave Opdahl <dopdahl@v3inc.com>

Like many of your other visitors I found your site quite useful. Your hard work hasn't gone unappreciated.

I made use of your TAP protocol page and wanted to give a little back.

Here is a checksum routine in C++ that I wrote. Feel free to put it up on your site. The checksum is a little confusing as described in the specification, I did notice that recently you put up a BASIC example. The code below may not be extremely portable, but it may help some people out.

Keep up the good work!

//nChecksum is sum of all appropriate bytes in message
//csTemp is just a string that gets filled with the 3 checksum bytes

void CV3Page::CalcChecksumString(CString &csTemp, int nChecksum)
{
        BYTE nFirstChar, nSecondChar, nThirdChar;
        int nTemp;

        //Calculate the checksum values
        nThirdChar = (BYTE)(nChecksum & 0x000F);//LS 4 bits
        nSecondChar = (BYTE)(nChecksum & 0x00F0);//MS 4 bits of LowByte
        nSecondChar >>= 4;
        nTemp = nChecksum & 0x0F00;     //LS 4 bits of Hibyte
        nFirstChar = (BYTE)(nTemp >> 8);

        //Build up the checksum string...
        csTemp += (BYTE)(nFirstChar + 0x30);
        csTemp += (BYTE)(nSecondChar + 0x30);
        csTemp += (BYTE)(nThirdChar + 0x30);
}

Last updated on June 22, 1997
Return to Brad Dye's Paging Information Resource