using System;
class Program
{
static void Main()
{
byte[] data = { 0x01, 0x03, 0x00, 0x00, 0x00, 0x01 };
ushort crc = CalculateCRC16(data);
byte crcHigh = (byte)((crc & 0xFF00) >> 8);
byte crcLow = (byte)(crc & 0x00FF);
Console.WriteLine($"CRC16: {crcHigh:X2} {crcLow:X2}");
}
public static ushort CalculateCRC16(byte[] data)
{
ushort crc = 0xFFFF;
foreach (byte b in data)
{
crc ^= b;
for (int i = 0; i < 8; i++)
{
if ((crc & 1) != 0)
{
crc >>= 1;
crc ^= 0xA001;
}
else
{
crc >>= 1;
}
}
}
return crc;
}
}