Java中将16进制字符串转换成汉字
技术交流群:233513714
/**
* 将16进制字符串转换成汉字
* @param str
* @return
*/
public static String deUnicode(String str) {
byte[] bytes = new byte[str.length() / 2];
byte tempByte = 0;
byte tempHigh = 0;
byte tempLow = 0;
for (int i = 0, j = 0; i < str.length(); i += 2, j++) {
tempByte = (byte) (((int) str.charAt(i)) & 0xff);
if (tempByte >= 48 && tempByte <= 57) {
tempHigh = (byte) ((tempByte - 48) << 4);
} else if (tempByte >= 97 && tempByte <= 101) {
tempHigh = (byte) ((tempByte - 97 + 10) << 4);
}
tempByte = (byte) (((int) str.charAt(i + 1)) & 0xff);
if (tempByte >= 48 && tempByte <= 57) {
tempLow = (byte) (tempByte - 48);
} else if (tempByte >= 97 && tempByte <= 101) {
tempLow = (byte) (tempByte - 97 + 10);
}
bytes[j] = (byte) (tempHigh | tempLow);
}
String result = null;
try {
result = new String(bytes, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return result;
}
Java中将16进制字符串转换成汉字的更多相关文章
- iOS 16进制字符串转换成int十进制
NSRange rangeErr; rangeErr.location = 6; rangeErr.length = 2; NSString *strings = [value substringWi ...
- C++实现16进制字符串转换成int整形值
开发中经常需要把16进制字符串转换成整形,写了个个代码供大家参考下: #include <stdio.h> #include <string.h> //字符转换成整形 int ...
- 字节流、字符串、16进制字符串转换__Java(转)
/** * @Package: * @ClassName:TypeConversion * @Description:字节流.字符串.16进制字符串转换 * @author:xk * @date:Ja ...
- 字节流、字符串、16进制字符串转换__java
package com.dvn.li.main; /** * @Package: * @ClassName:TypeConversion * @Description:字节流.字符串.16进制字符串转 ...
- java中 16进制字符串 与普通字符串 与 byte数组 之间的转化
方法依赖commons-codec包 maven的引入方式如下 <dependency> <groupId>commons-codec</groupId> < ...
- 字节数组(byte[])与16进制字符串转换
/// <summary> /// 转换扩展类 /// </summary> public static class ConvertExtend { /// <summa ...
- 16进制色值转换成RGB
#51147f 转换成RGB ,5*16+1 ,1*16+4,7*16+15 #A9A9A9 转换成RGB ,A*16+9 ,A*16+9,A*16+9
- 将16进制颜色转换成UIColor-ios
-(UIColor *) hexStringToColor: (NSString *) stringToConvert { NSString *cString = [[stringToConvert ...
- C#字符串和16进制字符串之间的转换
将字符串编码成 16进制 字符串表示: using System;using System.Collections.Generic;using System.Linq;using System.Tex ...
随机推荐
- SharePoint 2010 BCS - 概述
博客地址 http://blog.csdn.net/foxdave SharePoint 2010首次引入了BCS的概念 - Business Connectivity Service,即业务连接服务 ...
- Windows下LDAP服务器配置
LDAP即轻量级目录访问协议(Lightweight Directory Access Protocol),基础知识不再赘述,本文主要记录我的配置与安装过程. LDAP for windows下载 o ...
- 虚拟机无法上网的问题:无法启动VMnet0等问题
虚拟机无法上网,由于之前安装过虚拟机,后来将它卸载了,然后重新安装,最后出现了虚拟机无法上网.刚开始以为是系统的原因,于是就通过linux命令查看系统里面的网卡时是否启动,如:/etc/init.d/ ...
- ASP.NET中把xml转为dataset与xml字符串转为dataset及dataset转为xml的代码
转自:http://www.cnblogs.com/_zjl/archive/2011/04/08/2009087.html XmlDatasetConvert.csusing System;usin ...
- matlab 解方程组
1.解方程 最近有多人问如何用matlab解方程组的问题,其实在matlab中解方程组还是很方便的,例如,对于代数方程组Ax=b(A为系数矩阵,非奇异)的求解,MATLAB中有两种方法:(1)x=in ...
- Android如何分析和研究Monkey Log文件
Log 在android中的地位非常重要,要是作为一个android程序员不能过分析log这关,算是android没有入门吧 . 下面我们就来说说如何处理log文件 . 什么时候会有Log文件的产生 ...
- Margaritas on the River Walk_背包
Description One of the more popular activities in San Antonio is to enjoy margaritas in the park alo ...
- Magento中,调用静态块的几种方法
在后台创建一个order_form静态块Block Title :Order FormIdentifier :order_formStatus :EnabledContent :自定义内容 1.如果要 ...
- 阅读<构建之法>第三10、11、12章
第10章:典型用户和场景 阅读了第10章之后,我知道典型用户很重要,典型用户是某类群体的代表,他们的观点能够反映一类人的观点与对产品的要求,那么要怎么样才能够从一类群体里,选择正确的典型用户反映我们研 ...
- NSData和NSString 、 NSFileManager
1 NSData和NSMutableData的基本使用 1.1 问题 NSData类是IOS提供的用于以二进制的形式操作文件数据的类,NSData有两个常用的属性length和bytes,length ...