【发布时间】:2017-10-24 06:43:18
【问题描述】:
情况:
我有一个 GUI,我已经将水平十六进制转换为 ASCII...但现在我想将垂直十六进制转换为 ASCII。
有没有人知道如何解决这个问题?
我已经拆分了:
vert.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fintext5.setText("");
String[] test = entertext3.getText().split("\\n");
for(int i = 0; i<test.length; i++){
System.out.prinln(test[i]);
}
}
});
水平十六进制代码:
button5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fintext5.setText("");
String readout = entertext3.getText().replace(" ", "").replace("\n", "");
StringBuilder output = new StringBuilder("");
for (int i = 0; i < readout.length(); i += 2)
{
String str = readout.substring(i, i + 2);
output.append((char) Integer.parseInt(str, 16));
}
fintext5.append(output.toString());
}
});
垂直十六进制示例(41 42 43 44 45 46):
4 4 4
1 2 3
4 4 4
4 5 6
【问题讨论】:
-
你能举例说明这个“垂直十六进制”是什么吗?
-
好吧,如果
test[0].charAt(0)是第一个 ASCII 的 first 数字,您认为在哪里可以找到它的 second 数字第一个 ASCII 码? -
也许是 test[1].chatAt(0) ?
-
但是我如何在一个循环中得到这个?我不知道我会有多少行。
-
你当然知道:
test.length。唯一棘手的是您的外部循环需要以 2 为步长,例如for (int i = 0; i < test.length; i+=2)。
标签: java type-conversion hex ascii