The conversion of Java Chinese characters and 16 binary __java

Source: Internet
Author: User

public class Util {
public static string Deunicode (String content) {//convert 16 number to Chinese characters
String Enunicode=null;
String Deunicode=null;
for (int i=0;i<content.length (); i++) {
if (enunicode==null) {
Enunicode=string.valueof (Content.charat (i));
}else{
Enunicode=enunicode+content.charat (i);
}
if (i%4==3) {
if (enunicode!=null) {
if (deunicode==null) {
Deunicode=string.valueof ((char) integer.valueof (Enunicode). Intvalue ());
}else{
Deunicode=deunicode+string.valueof ((char) integer.valueof (Enunicode). Intvalue ());
}
}
Enunicode=null;
}

}
return deunicode;
}
public static string Enunicode (String content) {//converting Chinese characters to 16 numbers
String Enunicode=null;
for (int i=0;i<content.length (); i++) {
if (i==0) {
Enunicode=gethexstring (integer.tohexstring (Content.charat (i)). toUpperCase ());
}else{
Enunicode=enunicode+gethexstring (integer.tohexstring (Content.charat (i)). toUpperCase ());
}
}
return enunicode;
}
private static string gethexstring (String hexstring) {
String hexstr= "";
for (int i=hexstring.length (); i<4;i++) {
if (I==hexstring.length ())
hexstr= "0";
Else
hexstr=hexstr+ "0";
}
return hexstr+hexstring;
}

}

Here is the test class

public class Test1 {

/**
* @param args
*/
public static void Main (string[] args) throws Exception {
String str= "Wang Jiangpo is a little friend, Hohohoho";
SYSTEM.OUT.PRINTLN (Util.enunicode (str));
Print out 738b6c5f6ce2662f4e004e2a5c0f670b53cbff0c0048004f0048004f0048004f0048004f
Str= "738b6c5f6ce2662f4e004e2a5c0f670b53cbff0c0048004f0048004f0048004f0048004f";
SYSTEM.OUT.PRINTLN (Util.deunicode (str));
Print out Wang Jiangpo is a little friend, Hohohoho
}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.