How to Calculate the Checksum Byte of a General Field

ID: Q129534

The information in this article applies to:

SUMMARY

When a bitmap is appended to a general field, the actual information of the general field is stored in the associated .FPT file. The .FPT file holds the bitmap information followed by four bytes. The first of these four bytes is a checksum byte. The next three bytes are: AD 05 FE in hex.

This article lists the C code that writes the checksum byte to enable programmers to write their own General fields manually if so desired.

MORE INFORMATION

The checksum byte is calculated by FoxPro by using the following C code:

static unsigned char ObjectCheckSum = 0;

 //+-----------------------------------------------------------------------
 //
 //  Function: CalcCkSum, private
 //
 //  Synopsis:  Calculates the checksum for a general field.
 //
 //  Arguments: [ptr] -- pointer to data to calculate checksum on.
 //             [cb] -- number of bytes in the buffer.
 //
 //  Modifies:  ObjectCheckSum
 //
 //------------------------------------------------------------------------

 LOCAL void CalcCkSum(void *ptr, long cb)
 {
    long cktemp = 0;
    long cl = cb >> 2;
    long *lp = (long *) ptr;
    TEXT *cp;

    while(cl--)
       cktemp ^= *lp++;
       cl = cb & 3;  // Any remainder?
       cp = (TEXT *)lp;
    while(cl--)
       cktemp ^= *cp++;

    ObjectCheckSum ^= cktemp;
    ObjectCheckSum ^= cktemp >> 8;
    ObjectCheckSum ^= cktemp >> 16;
    ObjectCheckSum ^= cktemp >> 24;
  }

Additional reference words: FoxWin 2.60a KBCategory: kbprg kbcode KBSubcategory: FxprgGeneral

Last Reviewed: June 27, 1995