function CalCRC16 (Adata:array of Byte; Astart, Aend:integer): string;
Const
genp=$8408; Polynomial formula x16+x15+x2+1 (1100 0000 0000 0101)//$A 001
Var
Crc:word;
I:integer;
Tmp:byte;
s:string;
Procedure Calonebyte (Abyte:byte); Calculates a 1-byte check code
Var
J:integer;
Begin
CRC:=CRC XOR Abyte; The data is different from the low 8 bits of the CRC Register or
For j:=0 to 7 do//checksum per
Begin
TMP:=CRC and 1; Remove the lowest bit
CRC:=CRC SHR 1; Register Shift Right One
CRC:=CRC and $7FFF; The highest position 0
If Tmp=1 then//detects the shifted-out bit, if 1, then with the polynomial XOR or
CRC:=CRC XOR GENP;
CRC:=CRC and $FFFF;
End
End
Begin
Crc:= $FFFF; Set the remainder to FFFF
For I:=astart to Aend do//check each byte
Calonebyte (Adata[i]);
S:=inttohex (crc,2);
result:= rightstr (s,2) +leftstr (s,2);
End
Conversion functions
function TFORM1.STRTOCRC (s:string): string;
Var
BUF1:ARRAY[0..256] of Byte;
I:integer;
strorder:string;
res:string;
Begin
Strorder: =stringreplace (S, ', ', [Rfreplaceall]);
For i:=0 to (length (strorder) div 2-1) do
buf1[i]:= HexToInt1 (Copy (Strorder, i*2 +));
RESULT:=S+CALCRC16 (Buf1,low (BUF1), Length (strorder) div 2-1);
End
Delphi CRC Check function