左晓为主开发手持机充值管理机
zuoxiao
2024-03-04 a9c1231be4e3c1c5bd5e9fc61489d55363090407
app/src/main/java/com/dayu/recharge/tools/HexUtil.java
@@ -1,6 +1,8 @@
package com.dayu.recharge.tools;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -139,6 +141,38 @@
        return Integer.toHexString(Float.floatToIntBits(value));
    }
    /**
     * 将带符号的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;
    }
    /**
     * 将byte数组转换为带符号的32位浮点数
     *
     * 低位在前高位在后
     *
     * @param value
     * @return
     */
    public static Float bytesToFloat(byte[] value) {
        ByteBuffer bufferLittleEndian = ByteBuffer.wrap(value);
        bufferLittleEndian.order(ByteOrder.LITTLE_ENDIAN);
        return bufferLittleEndian.getFloat();
    }
    /**
     * 十进制转16进制
     *
@@ -167,6 +201,7 @@
    /**
     * short10进制转16进制 低位在前高位在后
     *
     * @param number
     * @return
     */
@@ -186,9 +221,9 @@
    }
    /**
     * short10进制转16进制 低位在前高位在后
     *
     * @param number
     * @return
     */
@@ -202,20 +237,20 @@
    }
    /**
     * short16进制转10进制 低位在前高位在后
     *
     * @param hex
     * @return
     */
    public static short  getShort10To16LowHigh(String hex){
    public static short getShort10To16LowHigh(String hex) {
        try {
            String str = "";
            str = spaceHex(hex);
            str = HighLowHex(str);
            return (short) Integer.parseInt(str, 16);
        } catch (NumberFormatException e) {
           e.printStackTrace();
            e.printStackTrace();
        }
        return 0;
    }