From ffa0b8640fc644f3ced78a23a2a57f8c628f8bc5 Mon Sep 17 00:00:00 2001 From: zhaofeng233 Date: Sun, 14 Mar 2021 17:35:00 +0800 Subject: [PATCH] =?UTF-8?q?ByteHelper=E6=96=B0=E6=B7=BB=E5=8A=A0=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=B0=86byteArray=E8=BD=AC=E6=8D=A2=E6=88=90int16?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=9AbyteArrayToInt16()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/util/ByteHelper.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/util/ByteHelper.java b/src/main/java/util/ByteHelper.java index 2475796..134bb48 100644 --- a/src/main/java/util/ByteHelper.java +++ b/src/main/java/util/ByteHelper.java @@ -94,6 +94,16 @@ public class ByteHelper { } return value; } + //无符号byte[2]转int + public static int byteArrayToInt16(byte[]bytes){ + int value= 0; + //由高位到低位 + for (int i = 0; i < 2; i++) { + int offset= (bytes.length - 1 - i) * 8; + value +=(bytes[i] & 0x000000ff) << offset; //往高位游 + } + return value; + } /** * 无符号long转byte[]