unsigned int CalCrc(char * buffer,unsigned int count)
{
unsigned int i,j;
unsigned int    CrcValue = 0;
for(i=0;i<count;i++)
{
        
        CrcValue = CrcValue ^ ( buffer[i]  << 8 );         for (j = 0; j < 8; j++)
                 if (CrcValue & 0x8000)
                   CrcValue = (CrcValue << 1) ^ 0x1021;
                 else
               CrcValue = CrcValue << 1;
        }
return (CrcValue);
}
请问以上代码用delphi怎么写

解决方案 »

  1.   

    http://www.sxlist.com/techref/method/crc_delphi.htm
      

  2.   


    Function GetCRC(Buf:pchar;len:integer):DWord;
    var
      i,j:integer;
      temp:integer;
    begin
        Result := $0;
       //---------------------------------------------------------
       For i := 0 to len-1 do
       begin
         Result := Result xor (ord(Buf[i]) shl 8) ;
         //-------------------------------------------------------
         For j :=1 to 8 do
         begin
           temp := Result and $8000;
           Result := Result shl 1;
           if temp = 1 then Result := Result xor $1021;
         end;
         //-------------------------------------------------------
       end;
       //--------------------------------------------------------end;