/********************************************************************函数名:u_int GetCrc(u_char *cData,u_int nSize)
描述:CRC校验程序
输入参数:cData 校验的数组  nSize  数组的长度
返回值:CRC校验码
********************************************************************/
u_int GetCrc(u_char *cData,u_int nSize)
{
u_char i;
u_int crc=0;
u_int s_crc; while(nSize--)
{
for(i=0x80; i!=0; i/=2)
{
     if((crc&0x8000)!=0)
     {
     crc*=2;
      crc^=0x1021;
     } //余式CRC 乘以2 再求CRC
     else
crc*=2;     if(*cData & i) 
     crc^=0x1021; //再加上本位的CRC
    }
    cData++;
}
s_crc = crc/(16*16);
s_crc <<= 8;
s_crc |= crc%(16*16);
return s_crc;
}

解决方案 »

  1.   

    function GetCrc(cData: PByte; u_int nSize): LongWord; 
    var
      i: Byte; 
      crc: LongWord; 
    begin
      crc := 0;
      while nSize > 0 do
      begin 
        i := $80; 
        while i <> 0 do
        begin 
          if (crc and $8000) <> 0 then 
            crc := (crc shl 1) xor $1021 
          else 
            crc := crc shl 1; 
          if (cData^ and i) <> 0 then
            crc := crc xor $1021; 
          i := i shr 1;
        end; 
        Dec(nSize);
        Inc(cData); 
      end; 
      Result := crc div (16 * 16); 
      Result := Result shl 8; 
      Result := Result or (crc mod (16*16)); 
    end; 
      

  2.   

    随手改的,发现函数参数没改过来:function GetCrc(cData: PByte; nSize: LongWord): LongWord;
      

  3.   

    http://topic.csdn.net/u/20081126/10/4489cadb-c08d-4f6f-8784-865d2a8f0315.html看我的这个贴,能圆满解决你的问题