Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- CA-Clipper Tools . Books 1-3 - <b>com_crc()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 COM_CRC()
 Computes a Cyclic Redundancy Check (CRC) for the string
------------------------------------------------------------------------------
 Syntax

     COM_CRC(<cString>,[<nStart>],[<nPolynomial>])
        --> nCRCValue

 Arguments

     <cString>  Designates the character string for which a CRC is
     computed.

     <nStart>  Designates a starting value that is added to the CRC.
     This value is computed in order to form a CRC for multiple character
     strings.  The default value is 0.

     <nPolynomial>  Designates another polynomial.  The maximum is a 17-
     bit polynomial.  The default polynomial is CRC-16 X.25 (see below).

 Returns

     COM_CRC() returns the 16-bit CRC for <cString> as a numeric value
     between 0 and 65535.

 Description

     CYCLIC  REDUNDANCY  CHECK
     Many file transfer protocols use CRC for accurate error recognition.
     This CRC function offers you decisive help when programming your own
     protocols, like XMODEM or KERMIT.

     The specific CRC value always depends on the polynomial that you use.
     This information can be passed as an optional parameter in the form of
     an integer so that the function has almost universal utility.  The CRC
     16 X.25 polynomial used in X.25 systems,.  XMODEM is the default value
     used in the examples below.

     A few examples of polynomials:

     Table 3-1: The Different Polynomials
     ------------------------------------------------------------------------
     Type           Arguments Polynomial
     ------------------------------------------------------------------------
     Parity         3         2^1+1
     LCR-8          257       2^8+1
     CRC-12         5011      2^12+2^11+2^3+2^2 +2^1+1
     CRC-16 X.25    69665     2^16+2^12+2^5+1
     CRC-16         98309     2^16+2^15+2^2+1
     ------------------------------------------------------------------------

 Notes

     .  If <nStart> is not passed, then the loss of the previous
        CHR(0) out of <cString> is not detected by a later CRC review.  This
        can be avoided if <nStart> is given a starting value that is not
        equal to 0.

     .  A function called XMOBLOCK() is available for building XMODEM
        blocks.

 Examples

     .  These are simple CRC calculations:

        COM_CRC("abc")                 // 40406
        COM_CRC("cba")                 // 54260

     .  These are calculations for multiple strings:

        nCRC1 := COM_CRC("123")
        nCRC2 := COM_CRC("456", nCRC1)

        ? nCRC2 == COM_CRC("123456")   // .T., values are equal

     .  Form a block for data transmission.  The string is appended to
        the data:

        cData   := "ABCDEFGHIJKLMNOP"
        nCRC    :=  COM_CRC(cData)

        cCRCSTR := I2BIN(CRC)          // CRC as a string
        cCRCSTR := CHARSWAP(cCRCSTR)   // Exchange both bytes
        cBlock  := cData + cCRCSTR     // Transmission block

     .  The CRC must be 0 for the entire transmitted block!

        ? COM_CRC(cBlock)  = 0         // .T., when correctly
                                       // transmitted


See Also: XMOBLOCK()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson