Example for CRC16 ?
lukashaefliger
Posts: 9
Hello
Does anyone has a working example / function how to build CRC16-checksums?
Thanx :-)
Does anyone has a working example / function how to build CRC16-checksums?
Thanx :-)
0
Comments
Let?s look a t an example of a Cyclical Redundency Checking (CRC) CheckSum:
DEFINE_CALL 'CRC CALC' (LENGTH,STRING[30],H_CRC,L_CRC)
LOCAL_VAR COUNT1 COUNT2 CRC
{
CRC = 0
COUNT1 = 1
WHILE ( COUNT1 <= LENGTH )
{
COUNT2 = 1
CRC = CRC BXOR (STRING[COUNT1] * 256)
WHILE (COUNT2 < 9)
{
IF (CRC BAND $8000)
CRC = (CRC *2) BXOR $1021
ELSE
CRC = CRC * 2
COUNT2 = COUNT2 + 1
}
COUNT1 = COUNT1 + 1
}
H_CRC = CRC/256
L_CRC = CRC BAND 255
}
Here a 16 bit CheckSum is represented as the High and Low bytes. The first byte is multiplied by 256 and then BXORed with 0. The result is BANDed with $8000. If there is a 1 in the 16th bit the result is multiplied by 2 then BXORed with $1021, then the result is run through that process 7 more times. Then the second byte is BXORed with that result and that result is processed 8 times. This is repeated until all bits are done. Then we divide the 16 bits into two values, the High and Low CheckSum Bytes. The High by dividing and the Low by BANDing.
This example I found in paper "Bitwise Operations".
Edited: Use code below
Edited: Use code below
I testet the code from kphlight because i have very much strings to transmit & calculate.
It looks like the fastest way....
But i get some Errors:
Ref Error ^CRC16_LOOKUP Index 0 Line=135
DoNumberExpression - Error 2 Tk=0x2012 Line=135
GetNumber - Error 1 Tk=0x0000
RunCode - Address Mismatch 0x4050 0x000704 0x000706
The problem ist, that the (t = (crc16retVal / 16) BXOR crcString ) returns "516" or "0"
Is the initializer with $FFFF correct???
Greetings & thanx fo help:
Lukas
Here are cleaner chksum functions with lookup tables. It includes:
CRC16 (function crc16)
CRC16.CCITT (function crc16c)
CRC16.XMODEM (function crc16x)
CRC32 (function crc32)
I'm thinking about doing MD2/4/5, SHA1/256/384/512, Base64, CRC64.. anyone have any need of those?
I'd love an MD5. :-)
An implementation of Base64 can be found in i!-EquipmentMonitor, which is an "integration! Solutions" application and available for download from the AMX web site.
Take a look at i!-EquipmentMonitorOut.axi. The Base64 function included there is used for SMTP authentication (for sending emails from NetLinx).
Regards, Harald
If you really need to use MD5 there is a module that I wrote that will perform MD5 encryption. Wont give the source code for the module away for various reasons, but I will send you the token. Just email me...
Below is how to use the module...
Jeremy
Hello,
does anyone has an example for CRC16-checksum with a polynom 1002 ?
many thanks for help
I'm trying to implement the CRC16-CITT lookup as shown in the example, but getting a "Converting type [Long] to [INTEGER] when compiling. Sorry if this is a basic question, but really keen to use this checksum
Cheers
nCRC = TYPE_CAST(nCRC << 1); //no warning
nCRC = nCRC << 1; //Long to Integer warning.
its this line that seems to be causing the issue with Converting type [Long] to [INTEGER]
m_crc16c = g_pCRC16CcittTable[((m_crc16c >> 8) ^ crcString16c)+1] ^ (m_crc16c << 8);
This is actually documented as a CRC16-CITT checksum as well...
This seems to be compiling and producing a result I was looking for, although it seem to be inverted as I'm looking for $2C09 and getting $92C
little endian vs big endian I would expect...
Hello amx world,
Does anyone has a working example / function how to build CRC16-x25?
This is an example that I should calculate.
$00,$00,$03,$00,$12,$6c,$a5,$00,$00,$31,$31,$31,$31,$31,$31,$31,$31,$00 CRC low - CRC high ($D6,$2C)
Thanx.
http://www.mcgougan.se/universal_crc/
http://www.repairfaq.org/filipg/LINK/F_crc_v31.html
I realize that this a massive thread revival. How could this function be revised to calculate an 8 bit CRC?
Thank you!