‘liusuyi’
2023-09-16 165befbfdc284f873a7ab266dee772f957787947
src/main/java/com/ard/utils/other/ByteUtils.java
@@ -3,6 +3,7 @@
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.zip.CRC32;
/**
@@ -62,11 +63,9 @@
     */
    public static int bytesToDecimal(byte[] byteArray) {
        int decimalValue = 0;
        for (int i = 0; i < byteArray.length; i++) {
            decimalValue = (decimalValue << 8) | (byteArray[i] & 0xFF);
        }
        return decimalValue;
    }
@@ -74,15 +73,12 @@
     * byte数组转Double
     */
    public static double bytesToDouble(byte[] byteArray) {
        long longBits = 0;
        // 根据字节数组的长度和字节顺序,将字节数组转换为长整型
        for (int i = 0; i < byteArray.length; i++) {
            longBits |= (long) (byteArray[i] & 0xFF) << (8 * (byteArray.length - 1 - i));
        }
        // 使用Double.longBitsToDouble方法将长整型转换为Double类型
        return Double.longBitsToDouble(longBits);
        // 创建一个ByteBuffer并设置字节顺序为大端
        ByteBuffer buffer = ByteBuffer.wrap(byteArray);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        // 从ByteBuffer中获取double值
        double doubleValue = buffer.getDouble();
        return doubleValue;
    }
    /**