各种转码总结
来源:互联网 发布:学校机房网络限制 编辑:程序博客网 时间:2024/06/03 17:47
/**
* 二进制转十六进制
*
* @param b
* @return
*/
private static String byte2hex(byte[] b) {
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++) {
stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1) {
hs = hs + "0" + stmp;
} else {
hs = hs + stmp;
}
}
return hs.toUpperCase();
}
/**
* 十六进制字符串转化为2进制
*
* @param hex
* @return
*/
private static byte[] hex2byte(String hex) {
byte[] ret = new byte[8];
byte[] tmp = hex.getBytes();
for (int i = 0; i < 8; i++) {
ret[i] = uniteBytes(tmp[i * 2], tmp[i * 2 + 1]);
}
return ret;
}
/**
* 将两个ASCII字符合成一个字节; 如:"EF"--> 0xEF
*
* @param src0
* byte
* @param src1
* byte
* @return byte
* @see [类、类#方法、类#成员]
*/
private static byte uniteBytes(byte src0, byte src1) {
byte _b0 = Byte.decode("0x" + new String(new byte[] { src0 }))
.byteValue();
_b0 = (byte) (_b0 << 4);
byte _b1 = Byte.decode("0x" + new String(new byte[] { src1 }))
.byteValue();
byte ret = (byte) (_b0 ^ _b1);
return ret;
}
- 各种转码总结
- [转]各种Mysql技巧总结
- 各种总结
- 各种总结
- 各种WPF命令列表总结(转)
- 转 各种排序算法稳定性的总结
- Windows 各种计时函数总结(转)
- 总结:各种加锁方法对于Map .(转)
- 各种数据库连接的总结
- 总结flex各种用法
- 总结flex各种用法
- 各种排序算法总结
- 各种互斥量的总结
- 各种容器特点总结
- 各种经典算法总结
- 各种排序算法总结
- 各种排序算法总结
- 各种排序方法总结
- Consume a Web Service in ABAP
- 修改密码(update)
- 在一个activity中kill其他的activity及退出整个应用程序
- 一些常用的JS正则表达式--会慢慢添加
- SIP协议栈添加 PRACK 支持
- 各种转码总结
- 开源的bug tracker管理系统Mantis来管理追踪项目和产品.
- 常用shell命令
- 我的联系方式
- 毕业生如何选择OFFER?
- linux下S3C2410的DMA驱动程序开发
- struts2.1.6 tags 06
- HTML5--CSS3在线编辑工具 超酷!!!(24款非常实用的CSS3工具终极收藏)
- MBSFN参考信号设计