兼容win7版应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
875 B

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AIK.Common.AIKProtocol
{
public static class ProtocolHelper
{
public static ushort CalculateCRC16(IEnumerable<byte> data)
{
if (data == null || !data.Any())
return 0;
ushort crc = 0;
foreach (byte b in data)
{
crc ^= (ushort)(b << 8);
for (int i = 0; i < 8; i++)
{
if ((crc & 0x8000) != 0)
{
crc = (ushort)((crc << 1) ^ 0x1021);
}
else
{
crc = (ushort)(crc << 1);
}
}
}
return crc;
}
}
}