public class ByteBufferDemo {
public static void main(String[] args) {
System.out.print(getInt((short) -23432) + " ");
}
public static int getInt(short tmp) {//大端模式存放,高位放低字节,低位放高字节
short number = tmp;
byte[] temp = new byte[2];
temp[0] = (byte) (number >> 8);
temp[1] = (byte) (number); //short转字节数组
short temp0 = temp[0];
short temp1 = temp[1];
short tempRes = (short) (temp0 << 8);
short result = (short) (tempRes + (temp1 > 0 ? temp1 : temp1 & 0x00ff));//字节数组转short
return result;
}
}
Java基础之short型数字与字节数组互转
最新推荐文章于 2022-01-18 17:20:40 发布