Java ascii to hex
来源:互联网 发布:商业银行数据质量评估 编辑:程序博客网 时间:2024/06/05 11:43
表达 数字的ascii string 转换回原始的数字
public static final byte[] toHex (byte hash[]) {
byte[] bytes = new byte[hash.length/2];
int i;
int j = 0;
int len = ((int)(hash.length / 2 )) *2;
for (i = 0; i < len; i +=2 ) {
byte a = hash[i];
byte b = hash[i+1];
if(a >= '0' && a <= '9' )
a = (byte) (a - '0');
else
a = (byte)(a - 'A' + 10);
if(b >= '0' && b <= '9' )
b = (byte) (b - '0');
else
b = (byte)(b - 'A' + 10);
bytes[j] = (byte) (a*16 + b);
j++;
}
return bytes;
}
还有一种写法类似这样:
String output = hex.substring(i, (i + 2));
//convert hex to decimal
int decimal = Integer.parseInt(output, 16);
//convert the decimal to character
sb.append((char)decimal);
但执行 parseInt时候一直出现异常,搞崩溃程序。还是用我的原始转换代码吧,保证不出问题。
- Java ascii to hex
- hex to ascii
- hex to anscii or non-ascii string
- HEX与ASCII转换
- ascii互换hex
- BCD,HEX,ASCII编码
- ascii(hex)/aes_ecb
- java 中 byte Ascii Hex int short 字串之间的互转
- bmp to hex
- convert HEX to Char
- SOJ.Hex to Int
- convert Hex to Bin
- Set1_Challenge1_Convert hex to base64
- int to hex
- Hex to Assembled codes
- Hex与ASCII相互转换函数
- Hex和ASCII相互转换函数
- 串口的Hex/AscII发送与显示
- 黑马程序员_C语言中变量作用域问题
- iOS-计算两个经纬度之间的距离和方位
- 我的第一个博客
- 福昕软件开发有限公司 Android笔试题
- WCF开发实战系列一:创建第一个WCF服务
- Java ascii to hex
- CCTouchDispatcher测试总结
- 开源库android-async-http添加https请求方式
- 浅谈JavaScript的事件机制
- Xcode Architectures配置
- 患得患失的人生
- WCF开发实战系列二:使用IIS发布WCF服务
- Ubuntu使用问题集及解决方案(不定期更新)
- 裁剪eps文件