ByteHelper新添加一个将byteArray转换成int16的方法:byteArrayToInt16()

This commit is contained in:
zhaofeng233
2021-03-14 17:35:00 +08:00
parent a0aa958303
commit ffa0b8640f
+10
View File
@@ -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[]