From c8b6f74ecc29022a7f52a2ee35aa25eef3312f39 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期三, 25 十月 2023 17:09:15 +0800
Subject: [PATCH] 海康动态链接库集成

---
 src/main/java/com/ard/utils/other/ByteUtils.java |   18 +++++++-----------
 1 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/ard/utils/other/ByteUtils.java b/src/main/java/com/ard/utils/other/ByteUtils.java
index 752b333..b82cd85 100644
--- a/src/main/java/com/ard/utils/other/ByteUtils.java
+++ b/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鏁扮粍杞珼ouble
      */
     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鏂规硶灏嗛暱鏁村瀷杞崲涓篋ouble绫诲瀷
-        return Double.longBitsToDouble(longBits);
+        // 鍒涘缓涓�涓狟yteBuffer骞惰缃瓧鑺傞『搴忎负澶х
+        ByteBuffer buffer = ByteBuffer.wrap(byteArray);
+        buffer.order(ByteOrder.LITTLE_ENDIAN);
+        // 浠嶣yteBuffer涓幏鍙杁ouble鍊�
+        double doubleValue = buffer.getDouble();
+        return doubleValue;
     }
 
     /**

--
Gitblit v1.9.3