CRC算法

function getCrc(s:shortstring):String; var len,i:integer; CRC16:word; begin crc16:=0; len:=length(s); for i:=1 to len do begin if (s[i]<>'') and (s[i]<>'|') then mybytecrc(ord(s[i]),crc16); end; Result:=inttohex(crc16,4); end; procedure MyByteCrc(data:byte;var crc:word); var i:byte; begin for i:=0 to 7 do begin if ((data and $01) xor (crc and $0001) <> 0) then begin crc:=crc shr 1; crc:=crc xor $A001; end else crc:=crc shr 1; data:=data shr 1; end; end; function gen_crc(const Buffer: array of Byte; const BufferLength: Smallint): Word; //CRC算法 var c,treat, bcrc: Byte; wcrc: Word; i,j: Smallint; begin wcrc := 0; i := 0; while i < BufferLength do begin c := Buffer[i]; for j := 0 to 7 do begin treat := c and $80; c := c shl 1; bcrc := (wcrc shr 8) and $80; wcrc := wcrc shl 1; if treat <> bcrc then wcrc := wcrc xor $1021; end; i := i + 1; end; gen_crc := wcrc; end;

你可能感兴趣的:(CRC算法)