我正在分析别人的代码。有人可以解释一下这是什么吗?

时间:2019-12-17 07:08:25

标签: c#

有人可以解释一下我做什么吗?

private int Crc(int BufLen, byte[] Buffer)
{
    byte i;
    byte Tmp;
    nt CrcVal = 0;
    for (i = 0; i < BufLen; i++)
    {
        Tmp = (byte)(((byte)CrcVal) ^ Buffer[i]);
        CrcVal = (CrcVal >> 8) ^ Crc16tab[Tmp];
    }
    return CrcVal;
}

private int[] Crc16tab = new int[256] 
{
    0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
    ...
}

我不明白这是什么意思。

以及为什么crc等于18513

-BuforSend [BuforSend.Length-2] = 81

-BuforSend [BuforSend.Length-1] = 72

protected override void SetChecksum()
{
    int crc = Crc(BuforSend.Length - 2, BuforSend);
    BuforSend[BuforSend.Length - 2] = (byte)(crc & 0xff);
    BuforSend[BuforSend.Length - 1] = (byte)((crc >> 8) & 0xff);
}

0 个答案:

没有答案