记录一下十六进制转字符串,以备以后使用方便
//十六进制转字符串utf-8
//字符串转十六进制utf-8
//十六进制转字符串utf-8
public static String hexToString(String hex) throws UnsupportedEncodingException
{
byte[] b=new byte[hex.length()/2];
for(int i=0;i<b.length;i++)
{
b[i]=(byte)(0xff&Integer.parseInt(hex.substring(i*2, i*2+2), 16));
}
return new String(b,"utf-8");
}
//字符串转十六进制utf-8
public static String stringToHex(String s)
{
String str="";
byte[] b=s.getBytes(Charset.forName("utf-8"));
for(int i=0;i<b.length;i++)
{
str+=Integer.toHexString(b[i]&0xff);
}
return str;
}