小栢给大家谈谈汉字转换为数字编码,以及汉字编码转换怎么转应用的知识点,希望对你所遇到的问题有所帮助。

1、public class Util {/ 将16进制字符串数转换为汉字,可包含数字及符号 方 法 名:HexToUnicode 创 建 人: 创建时间:2015-12-11 下午2:58:48 修 改 人: 修改日期: @param content @return String/public static String HexToUnicode(String content) {String enUnicode = null;String deUnicode = null;for (int i = 0; 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, 16).intValue());} else {deUnicode = deUnicode + String.valueOf((char) Integer.valueOf(enUnicode, 16).intValue());}}enUnicode = null;}}return deUnicode;}/ 将汉字转换为16进制字符串数,可包含数字及符号 方 法 名:UnicodeToHex 创 建 人: 创建时间:2015-12-11 下午2:59:31 修 改 人: 修改日期: @param content @return String/public static String UnicodeToHex(String content) {String enUnicode = null;for (int i = 0; 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 if (i == hexString.length())hexStr = "0";elsehexStr = hexStr + "0";}return hexStr + hexString;}public static void main(String[] args) {System.out.println(Util.UnicodeToHex("小王"));// 打印出// 738B6C5F6CE2662F4E004E2A5C0F670B53CBFF0C0048004F0048004F0048004F0048004FString str = "5C0F738B";System.out.println(Util.HexToUnicode(str));// 打印出 王江波是一个小朋友,HOHOHOHO}}数字的编码和汉字的编码是不一样的两者之间转换没有意义。

2、汉字占用两个字节 数字占用一个字节。

本文到这结束,希望上面文章对大家有所帮助。