【发布时间】:2018-12-05 00:18:11
【问题描述】:
我在将十六进制值转换为正确的 char 值时遇到了一点问题。 所以我运行了一个wireshark,每次捕获一个十六进制值。值是这个(wireshark 中的原始数据)。
00383700177a0102081c42000000000000018fffffff7f030201000a080000000000000000184802000007080444544235508001000002080104
所以现在我尝试向设备发送相同的命令。我使用此代码将十六进制转换为 ascii
String hex4 = "00383700177a0102081c42000000000000018FFFFFFF7F030201000a080000000000000000184802000007080444544235508001000002080104";
StringBuilder output4 = new StringBuilder();
for (int i =0; i< hex4.length(); i +=2){
String str4 = hex4.substring(i, i+2);
System.out.println(str4);
output4.append((char)Integer.parseInt(str4, 16));
}
bw3.write(output4.toString());
log.info(output4.toString());
bw3.flush();
但现在的问题是......当我在 Wireshark 中捕获自己发送的数据时,我得到了这个:
00383700177a0102081c4200000000000001c28fc3bfc3bfc3bf7f030201000a08000000000000000018480200000708044454423550c2800100
出于某种原因,我的代码发送了错误的 8f 和 ff 数据..
你能帮我解决问题吗? 谢谢 !
【问题讨论】:
-
my code send the 8f and ff data wrong不是很清楚。你能解释一下期望的输出或行为吗? -
8f 和 ff 不代表 ASCII 码单元。 (它们仅从 00 到 7f。)您为什么认为您仍然在接收 ASCII?而且,为什么要将它转换为 ISO 8859-1?你确定它是文字吗?