65 of 286
51 Rocksoft Model Parameters for Common CRC Algorithms Parameter/Type CRC-16 CRC-CCITT ModBus CRC-32 WIDTH 16 16 16 32 POLY &H8005 &H1021 &H8005 &H04c11db7 INIT &H0000 &Hffff &Hffff &Hffffffff REFIN True False True True REFOUT True False True True XOROUT &H0000 &H0000 &H0000 &Hffffffff CHECK &Hbb3d &H29b1 &H4b37 &Hcbf43926 The parameters are included in the table above for the CRC-32 algorithm but, of course, they must be used with the CRC32() function. The CHECK value is the CRC result for the string of characters "123456789". Additional information on CRC calculations may be found in many places on the Internet. One useful site that implements a CRC calculator is http://www.zorc.breitbandkatze.de/crc.html. If you don’t know the parameters required for a particular CRC, you may be able to deduce the correct parameters by using the calculator if you have a sample message and its CRC value. One of the variables available in the CRC calculator on the web page mentioned is “direct” vs. “nondirect”. This implementation uses the “direct” method. Example Dim data(1 to 20) as Byte Dim crc as UnsignedInteger ' compute the CRC using the CRC-16 algorithm crc = CRC16(data, 10, &H8005, &H0000, zxCRCRefIn Or zxCRCRefOut) Compatibility This function is not available in BasicX compatibility mode. Also, on ZX models that are based on the ATmega32 processor (e.g. the ZX-24) this function is implemented in “user code” (as opposed to being part of the VM) and is consequently slower than on other ZX models. See Also CRC32