mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-18 03:40:25 +08:00
ByteHelper新添加一个将byteArray转换成int16的方法:byteArrayToInt16()
This commit is contained in:
@@ -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[]
|
||||
|
||||
Reference in New Issue
Block a user