哪位大哥有CRC16的算法啊,是Delphi写的,我手上有一段C的算法不会转成Delphi,急啊!

解决方案 »

  1.   

    //Cyclic Redundancy Check Code 循环冗余检查码
    //公式 crc16=X16+x15+X5+x2+1
    //dword : 32 bits, word: 16 bits
    function CRC16(data:dword):word;
     var
       f,crc:dword;
       i:Cardinal;
    begin
       result:=$00;
       f:=$80000000;   //判断1,0的指标, 决定要左移多少位
       crc:=$C0128000; //32 bits ,(16bits:=$18025)
       i:=0;          //crc16=X16+x15+X5+x2+1
       data:=data shl 16;     //左移16位数
       repeat
         if (f and data) = 0 then
          begin
            inc(i);
            data:=data shl 1;  //左移1位数
          end else
          begin
           data:=data xor crc;
          end;
       until (i > 15);
        result:=data shr 16; //右移16位
    end;
    搂主看看是不是~