CRC-16/XMODE X16+X12+X5+1 C#环境下实现

private byte[] CRC(byte[] x, int len) //CRC校验函数
{
byte[] temdata = new byte[2];
UInt16 crc = 0;
byte da;
int i = 0;
UInt16[] yu = { 0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef };
while (len-- != 0)
{

da = (byte)(((byte)(crc / 256)) / 16);
crc <<= 4;
crc ^= yu[da ^ x[i] / 16];
da = (byte)(((byte)(crc / 256)) / 16);
crc <<= 4;
crc ^= yu[da ^ x[i] & 0x0f];
i++;
}
temdata[0] = (byte)(crc & 0xFF);
temdata[1] = (byte)(crc >> 8);
return temdata;
}

CRC-16/XMODE X16+X12+X5+1 C#环境下实现

上一篇:C#定义委托函数实现在别的窗体中操作主窗体中的SerialPort控件


下一篇:C#的OpenFileDialog和SaveFileDialog的常见用法(转)