以下代码在Windows 10 64位计算机上作为jar文件运行时工作正常但是当我将jar文件复制到RPI时,它始终生成错误消息错误。我尝试了从上面的链接使用JAVAW的建议但是在RPI上找不到命令。 IOW,无法在RPI上正确计算校验和。有关如何解决此问题的任何建议吗?
int messageBody[] = new int[(messageLen / 2) - 2];
checkSum = 0;
for (int charPtr = 2; charPtr < messageLen; ) {
firstChar = theMessage.charAt(charPtr++);
secondChar = theMessage.charAt(charPtr++);
theValue = ((firstChar >= 'A' ? (firstChar - 'A') + 10 : (firstChar - '0')) << 4)
| (secondChar >= 'A' ? (secondChar - 'A') + 10 : (secondChar - '0'));
if (messagePtr < messageBody.length) {
checkSum += theValue;
messageBody[messagePtr++] = theValue;
continue;
}
// Compute checksum
checkSum = (-checkSum & 0xff);
if (checkSum != theValue) {
System.err.println(System.lineSeparator() + "Check sum on received UPB packet failed -- should be " + checkSum + " but received as " + theValue);
System.err.println(System.lineSeparator() +" BAD MESSAGE[" + theMessage + "], " + theMessage.length() + " bytes");
return;
}
}
答案 0 :(得分:0)
只有我想到的是不同的字符串编码...
答案 1 :(得分:-3)
用32/64位编写的java中的本机代码不可移植,我们需要在目标环境中重新编译。
参考网址 http://www.oracle.com/technetwork/java/hotspotfaq-138619.html#64bit_native_porting
嗨Grogi&amp;鲍勃S, 感谢您的投入。