发现错误的LRC

Found wrong LRC

我想为以下消息计算 LRC(在 JAVA 中):

String TLV1="003D6000010000544553543531333030303234FF8B6028DF0225DF82040C544553543531333030303234DF820803000160DF820903170222DF820A03172011D5";

我的 LRC 应该是 "D5" = 213 但我的代码计算出 232 :( 我不知道我哪里做错了。

public short calculateLRC()                         
{

    short LRC = 0;

    for (int i =2 ; i < TLV1.length()-2; i=i+2)
    {
    String a1=TLV1.substring(i,i+2);    
    String a2="0x"+a1;
    Integer a3 = Integer.decode(a2);
    int a4[] = new int [TLV1.length()];
    a4[i/2]=a3;
    LRC ^= a4[i/2];                             
    }                                           
    return  LRC;

}

更改您的代码

LRC ^= TLV[i]; //Says array required but string found

LRC ^= (byte)TLV.charAt(i);