1.16進制字符串轉float浮點數
String str = "415C568C"; BigInteger b = new BigInteger(str, 16); float value = Float.intBitsToFloat(b.intValue()); System.out.println(value);
輸出:13.77113
2.字節數組轉16進制字符串
byte[] bytes = new byte[4]; bytes[0] = 60; bytes[1] = 35; bytes[2] = -41; bytes[3] = 10; String str = Hex.encodeHexString(bytes);
System.out.println(str);
輸出:3c23d70a
3.16進制字符串轉字節數組
String hexStr = "3c23d70a"; byte[] bytes = new byte[hexStr.length() / 2]; for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) (0xff & Integer.parseInt(hexStr.substring(i * 2, i * 2 + 2), 16)); } System.out.println(Arrays.toString(bytes));
輸出:[60, 35, -41, 10]