下面的程序进行CRC_16的标准运算结果为什么不对

loveyou20088 2009-11-25 05:55:41
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;

}

}
}
...全文
45 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

111,123

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧