How can I calculate Longitudinal Redundancy Check (LRC)?

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

    I realize that this question pretty old, but I had trouble figuring out how to do this. It's working now, so I figured I should paste the code. In my case, the checksum needs to return as an ASCII string.

    public function getLrc($string)
    {
        $LRC = 0;
        // Get hex checksum.
        foreach (str_split($string, 1) as $char) {
            $LRC ^= ord($char);
        }
        $hex = dechex($LRC);
        // convert hex to string
        $str = '';
        for($i=0;$i

提交回复
热议问题