如何将16进制数字转换成字符串 java

如题所述

第1个回答  2019-10-12
使用这个方法可以传进去的16进制的数字组成的字符串转化为utf-8格式的字符串
public
static
String
toStringHex1(String
s)
{
byte[]
baKeyword
=
new
byte[s.length()
/
2];
for
(int
i
=
0;
i
<
baKeyword.length;
i++)
{
try
{
baKeyword[i]
=
(byte)
(0xff
&
Integer.parseInt(s.substring(
i
*
2,
i
*
2
+
2),
16));
}
catch
(Exception
e)
{
e.printStackTrace();
}
}
try
{
s
=
new
String(baKeyword,
"utf-8");//
UTF-16le:Not
}
catch
(Exception
e1)
{
e1.printStackTrace();
}
return
s;
}
相似回答
大家正在搜