Loading

C# CRC16

private static ushort Calc(byte[] data)
{
    ushort wCRC = 0;
    for (int i = 0; i < data.Length; i++)
    {
        wCRC ^= (ushort)(data[i] << 8);
        for (int j = 0; j < 8; j++)
        {
            if ((wCRC & 0x8000) != 0)
                wCRC = (ushort)((wCRC << 1) ^ 0x1021);
            else
                wCRC <<= 1;
        }
    }
    return wCRC;
}
posted @ 2023-03-14 10:07  Stay627  阅读(58)  评论(0编辑  收藏  举报