byte间的异或处理 ----- 在线等
strSend 是穿进去的字符串,这个串很长,下面只写出来一部分,为什么有的时候算的结果是对的,有的时候是错的呢
在线等高手看看,谢谢
/ **
* 异域校验帧结果
*/
public void XorResult(String strSend){
strSend = "1A 14 04 03 15 016 0C 12 00 0F 0E 0D 0C 0B 0A 09 08 0A 02 05 16 12 1A 1F 15";
String strValue[] = strSend.split(" ");
byte strBat[] =new byte[strValue.length] ;
for(int i=0;i<strValue.length;i++)
{
strBat[i] = (byte) Long.parseLong(strValue[i],16);
}
// byte a[] = strSend.getBytes();
int ChkSum = 0;
for (int i = 0; i < strBat.length ; i++) {
if(i>0){
if(i == 1){
ChkSum = (int) (strBat[i]);
}else{
ChkSum = (int) (ChkSum ^ strBat[i]);
}
}
}
String ssXorResult = Integer.toHexString(ChkSum);
// XorResult = ssXorResult.substring(ssXorResult.length()-3,ssXorResult.length());
XorResult = ssXorResult.replaceAll("[a-zA-Z]","");
if(XorResult.length() == 1){
XorResult = "0"+XorResult;
}
XorResult = XorResult+" ";
}