解决方案 »

  1.   

            /// <summary>
            ///CRC16校验算法,(低字节在前,高字节在后)
            /// </summary>
            /// <param name="data">要校验的数组</param>
            /// <returns>返回校验结果,低字节在前,高字节在后</returns>
            public static byte[] crc16(byte[] data)
            {
                if (data.Length == 0)
                    throw new Exception("调用CRC16校验算法,(低字节在前,高字节在后)时发生异常,异常信息:被校验的数组长度为0。");
                byte[] temdata = new byte[data.Length + 2];
                int xda, xdapoly;
                byte i, j, xdabit;
                xda = 0xFFFF;
                xdapoly = 0xA001;
                for (i = 0; i < data.Length; i++)
                {
                    xda ^= data[i];
                    for (j = 0; j < 8; j++)
                    {
                        xdabit = (byte)(xda & 0x01);
                        xda >>= 1;
                        if (xdabit == 1)
                            xda ^= xdapoly;
                    }
                }
                temdata = new byte[2] { (byte)(xda & 0xFF), (byte)(xda >> 8) };
                return temdata;
            }
            #endregion
        }
    用这个试试。
      

  2.   

    http://bbs.csdn.net/topics/390869983这个帖子是我以前的你看下有没有帮助...
      

  3.   

    应该是 CRC16 查表法,但delphi不熟,不知道该如何转。
    在网上找到了这篇文章
    http://www.cnblogs.com/armyfai/p/3566144.html
      

  4.   

    delphi
     crc:= (crc shr 8) xor CRCtbl[(crc xor dzp1^) and $ff];C#
     crc =(crc >> 8) ^ CRCtbl[(crc ^ data[i]) & 0xff];这两句执行后,得到的CRC不一样,郁闷死了。 感觉这样写没有问题啊
      

  5.   

    crc = 65535;Delphi :  
        a := crc shr 8;
        a = 30667;C#:
      ushort a = (ushort)(crc >> 8);
      a = 255;这是为什么呢??????