怎么将十六进制字符串:0020000000c00012 转换成:0x00 0x20 0x00 0x00 0x00 0xc0 0x00 0x12 .
怎么将十六进制字符串:0020000000c00012 转换成:0x00 0x20 0x00 0x00 0x00 0xc0 0x00 0x12 . 最好有代码.
------解决方案--------------------Byte的范围是:-127到128,你上面的0xc0对于Byte,已经溢出.
参考代码:
package net.oicp.sunflowerbbs;
public class Ahex {
static Byte[] Convert(String str) {
int len = str.length();
Byte[] result = new Byte[(int)Math.round(len/2.0D)];
int k=0;
for (int i = 0; i < len; i += 2) {
String tmp = str.substring(i, i + 2 > len ? i + 1 : i + 2);
Long hex = Long.parseLong(tmp, 16);
result[k]=hex.byteValue();
System.out.println(result[k]);
k++;
}
return result;
}
public static void main(String[] args) {
Convert( "0020000000c00012 ");
}
}