知识储备

procedure TForm1.Button8Click(Sender: TObject);
var
   Cl,Ch,crc16Hi,Crc16Lo : byte;
   savehi,savelo : byte;
   flag,i : integer;
   rebuffer : array [1..5] of byte;
begin
//// 字符串
   rebuffer[1] := $01;
   rebuffer[2] := $03;
   rebuffer[3] := $02;
   rebuffer[4] := $00;
   rebuffer[5] := $CD;

/// 初始化
   crc16Hi := $FF;
   Crc16Lo := $FF;
   cl := $01;
   Ch := $A0;

/// 循环冗余
   for i := 1 to 5 do
   begin
       Crc16Lo := ((Crc16Lo xor rebuffer[i]));
       for flag := 1 to 8 do
       begin
          savehi := crc16Hi;
          savelo := Crc16Lo;
          crc16Hi := crc16Hi shr 1;
          Crc16Lo := Crc16Lo shr 1;
          if ((savehi and 1) = 1) then
          begin
              Crc16Lo := Crc16Lo or $80;
          end;

          if ((savelo and 1) = 1) then
          begin
              crc16Hi := (crc16Hi xor ch);
              Crc16Lo := (Crc16Lo xor Cl);
          end;
       end;
   end;
  ShowMessage(IntTohex(ord(crc16Hi),2) + '    ' + IntTohex(ord(Crc16Lo),2));
end;

你可能感兴趣的:(职场,Delphi,CRC,校验,休闲)