我想计算以下消息的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;
}发布于 2017-02-27 16:09:44
更改您的代码
LRC ^= TLV[i]; //Says array required but string found至
LRC ^= (byte)TLV.charAt(i);https://stackoverflow.com/questions/42479974
复制相似问题