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[]