How can I calculate Longitudinal Redundancy Check (LRC)?

前端 未结 6 872
盖世英雄少女心
盖世英雄少女心 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:15

    If someone wants to get the LRC char from a string:

        public static char CalculateLRC(string toEncode)
        {
            byte[] bytes = Encoding.ASCII.GetBytes(toEncode);
            byte LRC = 0;
            for (int i = 0; i < bytes.Length; i++)
            {
                LRC ^= bytes[i];
            }
            return Convert.ToChar(LRC);
        }
    

提交回复
热议问题