1.String 转 byte[ ]
String a = "我们123abc";
byte[] b = a.getbytes("utf-16(编码格式)");
2.byte[ ]转String 【16进制】
byte[] byteData = {字节数组};
char[] hexArray = "0123456789ABCDEF".toCharArray();
char[] hexChars = new char[byteData.length * 2];
for (int j = 0; j < byteData.length; j++) {
int v = byteData[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
String aa = new String(hexChars);
System.out.println(aa);
3.将16进制String转成可读String
Stringstr="000033338000000030303030303030330303138363";
byte[] byteArray = new byte[str.length() / 2];
for (int i = 0; i < byteArray.length; i++){
String subStr = str.substring(2 * i, 2 * i + 2);
byteArray[i] = ((byte)Integer.parseInt(subStr, 16));
}
String a = new String(byteArray,"utf-16");
System.out.println(a);