将Asci代码转换回相应的十六进制值 [英] Convert Asci code back to curresponding hex value
问题描述
大家好,
我需要323830303030346434313461343135383538346435323462343134343535333833303339333033363030303164346330303130313031313630343031303130353165303030653038316130643164303435323236
转换为2800004d414a4158584d524b41445538303930360001d4c001010116040101051e000e081a0d1d045226
其中32是2的asci,38的8。 30 of 0等
任何帮助?
非常感谢
Hi All,
I need to convert 323830303030346434313461343135383538346435323462343134343535333833303339333033363030303164346330303130313031313630343031303130353165303030653038316130643164303435323236
to 2800004d414a4158584d524b41445538303930360001d4c001010116040101051e000e081a0d1d045226
where 32 is the asci of 2 , 38 of 8 . 30 of 0 etc
Any help ?
Thanks alot
推荐答案
您只需要遍历每两位数字并将其首先转换为其基值:
You just need to go through each two digit number and convert it first to its base value thus:
if number >= 0x30 AND <= 0x39 // 0 to 9
number -= 0x30
else if number number >= 0x41 AND <= 0x46 // A to F
number = number - 0x41 + 10 // 10 to 15
else if number number >= 0x61 AND <= 0x66 // a to f
number = number - 0x61 + 10 // 10 to 15
然后将其添加到目标字段的下一个4位部分。
then add it to the next 4 bit portion of your destination field.
一次将字符串拆分为两个字符的集合。
整数解析基数为16的分割部分。
转换为char。
Split the string into sets of two characters at a time.
Integer parse at base 16 the split parts.
Convert to char.
package mypackage;
public class Program {
public static void main(String[] args) {
final String input = "323830303030346434313461343135383538346435323462343134343535333833303339333033363030303164346330303130313031313630343031303130353165303030653038316130643164303435323236";
final StringBuilder builder = new StringBuilder();
for(int i = 0; i < (input.length() - 1); i += 2) {
final String part = input.substring(i, i + 2);
final int intValue = Integer.parseInt(part, 16); // 16 for base 16 here
final char character = (char)intValue;
builder.append(character);
}
System.out.println(builder.toString());
}
}
希望这会有所帮助,
Fredrik
Hope this helps,
Fredrik
这篇关于将Asci代码转换回相应的十六进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!