using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Guidaoji { internal class ModbusCRC16 { public static ushort CalculateCrc(byte[] bytes) { const ushort polynomial = 0xA001; ushort crc = 0xFFFF; for (int i = 0; i < bytes.Length; i++) { crc ^= (ushort)(bytes[i] & 0xFF); for (int j = 0; j < 8; j++) { if ((crc & 0x0001) == 0x0001) { crc >>= 1; crc ^= polynomial; } else { crc >>= 1; } } } return crc; } } }