既不清楚了,
记得c做的时候是根据每个校验位进行操作,可能是&操作,
结果赋给第16位
校验的时候也是如此,看获得的结果和第16位的值是否相同

解决方案 »

  1.   

    http://www.ilib.cn/A-yysfxyxb200404012.html
      

  2.   

    using System;
    using System.Text;public sealed class CRC32
    {
    public const int TABLE_SIZE = 256; public const uint STANDARD_POLYNOMIAL = 0xedb88320; private CRC32()
    {
    } static CRC32() 
    {
    table = new uint[TABLE_SIZE];
    polynomial = STANDARD_POLYNOMIAL;
    } public static bool Initialized 
    {
    get { return initialized; }
    }
    [CLSCompliant(false)]
    public static uint Polynomial 

    get { return polynomial; }
    } private static uint[]    table;
    private static uint      polynomial;
    private static bool      initialized;
    public static void Init(uint Polynomial) 
    {
    polynomial = Polynomial;
    uint i = 0, j = 0;
    uint dwCRC = 0; for (i = 0; i < TABLE_SIZE; i++) 
    {
    dwCRC = i;
    for (j = 8; j > 0; j--) 
    {
    if ((dwCRC & 1) != 0) 
    dwCRC = (dwCRC >> 1) ^ polynomial;
    else
    dwCRC >>= 1;
    }
    table[i] = dwCRC;
    } initialized = true;
    } public static void Init(int Polynomial) 
    {
    byte[] intBytes = BitConverter.GetBytes(Polynomial);
    uint poly = BitConverter.ToUInt32(intBytes, 0);
    Init(poly);
    } public static void Init(long Polynomial) 
    {
    const uint Mask = 0xffffffff;
    uint  poly = (uint)(Polynomial & Mask);
    Init(poly);
    } public static void Init() 
    {
    Init(STANDARD_POLYNOMIAL);
    } public static byte[] Crc32(byte[] data) 
    {
    if (!initialized)
    throw new InvalidOperationException(
    "You must initialize the CRC table before attempting to calculate the check on data."); byte[] crc32_result;
    uint _result = 0, len = (uint)unchecked(data.Length);
    uint i = 0; const uint tableIndexMask = 0xff; uint dwCRC32 = 0xffffffff;
    for (i = 0; i < len; i++) 
    {
    dwCRC32 = (dwCRC32 >> 8) ^ table[ (uint)data[i] ^ (dwCRC32 & tableIndexMask) ];
    } _result = dwCRC32 ^ 0xffffffff; crc32_result = BitConverter.GetBytes(_result);
    return crc32_result;
    } public static unsafe byte[] Crc32(byte *pData, uint dwLength) 
    {
    byte* ptr = pData;
    byte[] data = new byte[dwLength];
    for (uint i = 0; i < dwLength; i++) 
    {
    data[i] = *ptr;
    ptr++;
    } return Crc32(data);
    } public static byte[] Crc32(string data) 
    {
    return Crc32(data, Encoding.ASCII);
    } public static byte[] Crc32(string data, Encoding encoding) 
    {
    byte[] encData = encoding.GetBytes(data);
    return Crc32(encData);
    }
    }  
      

  3.   

    能给一个数据吗,比如我byte[] crctest={1,0,0,1,0,1,0,1}这样用CRC算出来的校验码应是多少?
    我怎么才能确定算出来的数据是对的.
      

  4.   

    byte[] crctest={1,0,0,1,0,1,0,1}-500323098(0xE22DACE6) // CRC32
    17117(0x42DD) // CRC16
      

  5.   

    计算结果和cangwu_lee(橙子)一致