mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
ByteHelper新添加一个将byteArray转换成int16的方法:byteArrayToInt16()
This commit is contained in:
1 parent
a0aa958303
commit
ffa0b8640f
1 file changed
+10
@@ -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