/// <summary>
/// 计算CRC检验
/// </summary>
/// <param name="value"></param>
/// <param name="p"></param>
/// <param name="iCRC"></param>
/// <returns></returns>
public static List<byte> CRC16(List<byte> value, ushort p = 0xA001, ushort iCRC = 0xFFFF)
{
// 运算
ushort crc = iCRC;
for (int i = 0; i < value.Count; i++)
{
crc = (ushort)(crc ^ (value[i]));
for (int j = 0; j < 8; j++)
{
crc = (crc & 1) != 0 ? (ushort)((crc >> 1) ^ p) : (ushort)(crc >> 1);
}
}
byte h = (byte)((crc & 0xFF00) >> 8);
byte l = (byte)(crc & 0x00FF);
List<byte> buffer = new List<byte>();
buffer.AddRange(value);
buffer.Add(l);
buffer.Add(h);
return buffer;
}
标签:crc,buffer,ushort,List,检验,CRC,value,计算,byte
From: https://www.cnblogs.com/NingNingG/p/16807584.html