我想把0xffd0转成short类型,真实值应该为-32720,可是实际转出来的怎么是-48?求各位高手帮帮忙,下面是代码:
byte[] bytes = new byte[2];
bytes[0]=(byte)0xd0;
bytes[1]=(byte)0xff;
System.out.println((short) ((0xff & bytes[0]) | (0xff00 & (bytes[1] << 8))));
------解决方案--------------------
0xffd0&0x07FFF
这么做
------解决方案--------------------
public static void main(String[] args) {
int i=0xffd0;
int s;
if (i>0x7fff) {
s=-(i-0x8000);
} else {
s=i;
}
System.out.println(s);
}