String s="18a1a2";(s是十六进制数组成的字符串)
byte[] result = new byte[3] ;
怎么实现s每两位对应一个字节,即:
result[0]=(0x)18;
result[1]=(0x)a1;
result[2]=(0x)a2;
请哪位大神指教一下,谢谢
//string 转 byte[]
String str = "Hello";
byte[] srtbyte = str.getBytes();
// byte[] 转 string
String res = new String(srtbyte);
System.out.println(res);
//当然还有可以设定编码方式
的
String str = "hello";
byte[] srtbyte = null;
try {
srtbyte = str.getBytes("UTF-8");
String res = new String(srtbyte,"UTF-8");
System.out.println(res);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}