ACS-11-MF
User’s Manual (Ver.1.0, Apr./2016) ------------- 38
private byte[] CRC_16(byte[] data, int DataLength)
{
uint CRC_Polynomial = 0x1021;
uint CRC_Init = 0xFFFF;
for (int i = 0; i < DataLength; i++)
{
CRC_Init = CRC_Init ^ ((uint)data[i] << 8);
for (int j = 0; j < 8; j++)
{
if (System.Convert.ToBoolean(CRC & 0x8000))
CRC_Init = (CRC_Init << 1) ^ CRC_Polynomial;
else
CRC_Init = (CRC_Init << 1);
}
}
return HexStringToByteArray(Convert.ToString((UInt16)(CRC^ 0xFFFF), 16));
}
Example
:
Input: 0xAF, 0x01, 0x01
Data length: 3
Output
:
0xDE(CRCH), 0x81(CRCL)