Delphi CRC Check function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.