下面的程序进行CRC_16的标准运算结果为什么不对
using System;using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
public static void Main (string[] args)
{
byte[] CESHI = new byte[] { 1, 3, 0, 0, 0, 2 };
ushort d = CRC_16(CESHI);
Console.WriteLine(d);
Console.Read();
}
public static ushort CRC_16(byte[] CRC)
{
ushort a;
byte c, b;
a =CRC[0];
a <<= 8;
a += CRC[1];
for (int num=2; num < CRC.Length; num++)
{
for (int i = 0; i < 8; i++)
if (a >= 32768)
{
c = 128;
a <<= 1;
for (int j = 0; j < i; j++)
{
c >>= 1;
}
b =Convert .ToByte( CRC[num] & c);
b >>= 7-i;
a += b;
a ^= 0x1021;
}
else
{
c = 128;
a <<= 1;
for (int j = 0; j < i; j++)
{
c >>= 1;
}
b = Convert.ToByte(CRC[num] & c);
b >>= 7-i;
a += b;
}
}
return a;
}
}
}
补充:.NET技术 , C#