How can I calculate Longitudinal Redundancy Check (LRC)?

前端 未结 6 924
盖世英雄少女心
盖世英雄少女心 2021-01-19 07:35

I\'ve tried the example from wikipedia: http://en.wikipedia.org/wiki/Longitudinal_redundancy_check

This is the code for lrc (C#):

///          


        
6条回答
  •  忘掉有多难
    2021-01-19 08:05

    The corrected Wikipedia version is as follows:

    private byte calculateLRC(byte[] b)
        {
            byte lrc = 0x00;
            for (int i = 0; i < b.Length; i++)
            {
                lrc = (byte)((lrc + b[i]) & 0xFF);
            }
            lrc = (byte)(((lrc ^ 0xff) + 2) & 0xFF);
            return lrc;
        }
    

提交回复
热议问题