当前位置: 技术问答>java相关
超过范围的值java如何处理
来源: 互联网 发布时间:2014-12-31
本文导语: QUESTION 52/272: The following program uses bit shifting. What is the output from the following program? class BitShift { public static void main(String [] args) { int x = 0x80000000; System.out.print(x + " and "); x = x >> 31; Syst...
QUESTION 52/272:
The following program uses bit shifting. What is the output from the following program?
class BitShift {
public static void main(String [] args) {
int x = 0x80000000;
System.out.print(x + " and ");
x = x >> 31;
System.out.println(x);
}
}
A. -2147483648 and 1
B. 0x8000000 and 0xffffffff
C. -214783648 and -1
D. -1 and -214783648
E. None of the above
答案是c, 请高手为我解释一下,超过范围的值如何处理
The following program uses bit shifting. What is the output from the following program?
class BitShift {
public static void main(String [] args) {
int x = 0x80000000;
System.out.print(x + " and ");
x = x >> 31;
System.out.println(x);
}
}
A. -2147483648 and 1
B. 0x8000000 and 0xffffffff
C. -214783648 and -1
D. -1 and -214783648
E. None of the above
答案是c, 请高手为我解释一下,超过范围的值如何处理
|
负数用补码表示,表示为二进制正数取补然后加1
如1为0000,0000,0000,0001,求补后为1111,1111,1111,1110,加一为1111,1111,1111,1111就是-1
最高位是符号位,为1是负数
如1为0000,0000,0000,0001,求补后为1111,1111,1111,1110,加一为1111,1111,1111,1111就是-1
最高位是符号位,为1是负数
|
老兄,让这位小兄弟去看一些书好了,看上去他还有好多基础要补一补哪。:)
如有不什么不恭之处敬恕罪。
如有不什么不恭之处敬恕罪。