1、将整数转换为双字节数组
public static byte[] unsignedShortToByte2(int s) {
byte[] targets = new byte[2];
targets[0] = (byte) (s & 0xFF);
targets[1] = (byte) (s >> 8 & 0xFF);
return targets;
}
2、将双字节数组转换为整数
例如:整数45
第一种方式:int i = (4 & 0xFF) | (5 & 0xFF) << 8;
第二种方式:BigInteger value = new BigInteger(new byte[]{5,4});