【问题标题】:Found wrong LRC发现错误的LRC
【发布时间】:2017-02-27 07:25:38
【问题描述】:

我想为以下消息计算 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;

}

【问题讨论】:

标签: java android output tlv


【解决方案1】:

修改你的代码

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-05
    • 2017-11-18
    • 2013-02-27
    • 1970-01-01
    • 2013-06-01
    • 1970-01-01
    相关资源
    最近更新 更多