各种进制转换
来源:互联网 发布:苹果实用软件推荐 编辑:程序博客网 时间:2024/06/06 13:59
byte 转字符串
public static String hexString(byte b) {String hex = Integer.toHexString(b & 0xFF);if (hex.length() == 1) {hex = '0' + hex;}return hex;}
byte[] 转 字符串(这里提供两种方法)
public static String hexString(byte[] b) {StringBuffer sb = new StringBuffer();for (int i = 0; i < b.length; i++) {String hex = Integer.toHexString(b[i] & 0xFF);if (hex.length() == 1) {hex = '0' + hex;}sb.append(hex.toUpperCase());}return sb.toString();}
public static String bytesToHexString(byte[] src) {StringBuilder stringBuilder = new StringBuilder("");if ((src == null) || (src.length <= 0)) {return null;}for (int i = 0; i < src.length; ++i) {int v = src[i] & 0xFF;String hv = Integer.toHexString(v);if (hv.length() < 2) {stringBuilder.append(0);}stringBuilder.append(hv);}return stringBuilder.toString();}
转换十六进制编码为字符串
public static String toStringHex(String s) { if ("0x".equals(s.substring(0, 2))) { s = s.substring(2); } byte[] baKeyword = new byte[s.length() / 2]; for (int i = 0; i < baKeyword.length; i++) { try { baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring( i * 2, i * 2 + 2), 16)); } catch (Exception e) { e.printStackTrace(); } } try { s = new String(baKeyword, "utf-8");//UTF-16le:Not } catch (Exception e1) { e1.printStackTrace(); } return s; }
String类型转换byte[]
public static byte[] hexStringToByte(String hex) { int len = (hex.length() / 2); byte[] result = new byte[len]; char[] achar = hex.toCharArray(); for (int i = 0; i < len; i++) { int pos = i * 2; result[i] = (byte) (toByte(achar[pos]) << 4 | toByte(achar[pos + 1])); } return result; }
private static byte toByte(char c) { byte b = (byte) "0123456789ABCDEF".indexOf(c); return b; }
16进制转10进制
String X10 = Integer.valueOf(X16,16).toString();
10进制转2进制
String X2 = Integer.toBinaryString(Integer.parseInt(X10));
0 0
- 各种进制转换
- 各种进制转换
- 各种进制转换
- 各种进制转换
- 各种进制转换
- 各种进制转换
- 各种进制的转换
- php 各种进制转换
- java 各种进制 转换
- Java 各种进制转换
- Android各种进制转换
- VB 各种进制相互转换大全
- VB 各种进制相互转换大全
- VB 各种进制相互转换大全
- VB 各种进制相互转换
- C# 各种进制之间相互转换
- VB中各种进制的转换
- VB 各种进制相互转换大全
- Android常识性问题
- 关于在工作中遇到没处理过的问题,如何寻找解决方案
- jQuery之$.ajax()方法详解
- Spire.PDF API 可以在CSDN下载啦!
- PostMessage
- 各种进制转换
- Nodejs+Express创建HTTPS服务器
- WAPI安全协议检测系统V3解析:自动化、高效率、低成本
- SpringMvc教程(一)--SpringMvc的概述
- 安卓学习-活动(Activity)
- 正则表达式随笔
- 腾讯IM即时通讯(2.4.1)
- php读取目录文件函数is_dir(),opendir(),readdir(),closedir()
- 关于iOS10需要支持https才能通关苹果App Store审核问题