左晓为主开发手持机充值管理机
zuoxiao
2024-05-09 b8f8323cc39091d3119101923251a0455da87f55
baselibrary/src/main/java/com/dayu/baselibrary/tools/HexUtil.java
@@ -54,6 +54,7 @@
    /**
     * byte 数组转16进制字符串 不加0前缀
     *
     * @param bytes
     * @return
     */
@@ -104,20 +105,6 @@
        return bufferLittleEndian.getFloat();
    }
    /**
     * 将带符号的32位浮点数装换byte数组
     * 低位在前高位在后
     *
     * @param value
     * @return
     */
    public static byte[] folatToByte(Float value) {
        ByteBuffer buffer = ByteBuffer.allocate(4); // 4个字节
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        buffer.putFloat(value);
        byte[] byteArray = buffer.array();
        return byteArray;
    }
    /**
     * hex字符串转byte数组
@@ -190,9 +177,6 @@
    }
    /**
     * 将 4字节的16进制字符串,转换为32位带符号的十进制浮点型
     *
@@ -213,6 +197,37 @@
        return Integer.toHexString(Float.floatToIntBits(value));
    }
    /**
     * float转Hex低位在前高位在后
     *
     * @param value
     * @return
     */
    public static String floatToHexLowHigh(Float value) {
        String hexString = Integer.toHexString(Float.floatToIntBits(value));
        hexString = spaceHex(hexString);
        hexString = HighLowHex(hexString);
        return hexString;
    }
    public static float hexToFloatLowHigh(byte[] data) {
        List<Byte> byteList = new ArrayList<>();
        for (byte b : data) {
            byteList.add(b);
        }
        Collections.reverse(byteList);
        byte[] byteArray = new byte[byteList.size()];
        for (int i = 0; i < byteList.size(); i++) {
            byteArray[i] = byteList.get(i);
        }
        String hex = bytesToHexNoAppen(byteArray);
        int intValue = Integer.parseInt(hex, 16); // 将十六进制字符串转换为整数表示
        float floatValue = Float.intBitsToFloat(intValue); // 将整数表示转换为浮点数
        return floatValue;
    }
    /**
     * 十进制转16进制
     *