The example of this article describes the implementation method of converting Chinese characters to unicode and converting Chinese characters to hexadecimal in Java. Share it with everyone for your reference. The specific implementation method is as follows:
1. Convert Chinese characters to unicode
Copy the code code as follows:
public static String toUnicode(String s)
{
String as[] = new String[s.length()];
String s1 = "";
for (int i = 0; i < s.length(); i++)
{
as[i] = Integer.toHexString(s.charAt(i) & 0xffff);
s1 = s1 + as[i]+"/t";
}
return s1;
}
2. Convert Chinese characters to hexadecimal
Copy the code code as follows:
public static String toChineseHex(String s)
{
String ss = s;
byte[] bt = ss.getBytes();
String s1 = "";
for (int i = 0; i < bt.length; i++)
{
String tempStr = Integer.toHexString(bt[i]);
if (tempStr.length() > 2)
tempStr = tempStr.substring(tempStr.length() - 2);
s1 = s1 + tempStr + " ";
}
return s1.toUpperCase();
}
I hope this article will be helpful to everyone’s Java programming.