赞
踩
前段时间当好要做一个Ble 读写。
其中就有进制转换。
bytesToHex();//byte数据转化成16进制字符串
- static final char[] hexArray = "0123456789ABCDEF".toCharArray();
-
- private static String bytesToHex(byte[] bytes) {
- char[] hexChars = new char[bytes.length * 2];
- for (int j = 0; j < bytes.length; j++) {
- int v = bytes[j] & 0xFF;
- hexChars[j * 2] = hexArray[v >>> 4];
- hexChars[j * 2 + 1] = hexArray[v & 0x0F];
- }
- return new String(hexChars);
- }
- //剪切字符得到相应字节里的数据(例子有高低位之分的,高在前,底在后)
- String L=bytesToHex(value).substring(6,8);
- String H=bytesToHex(value).substring(8,10);
- long ten_num = Long.parseLong(H+L, 16);//把并接的16进制字符串转换成10进制long
String strHex = Integer.toHexString(125); //把int值转换成16进制字符串
- //把整数字符串,转变成byte字节
- public static byte hexToByte(String inHex) {
- return (byte) Integer.parseInt(inHex, 16);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。