不好意思,此前问的那个打错了。
我在做一个SCJP的题。如下
After execution of the following code, what is the value of a?
byte a;
byte b = 3; // binary 00000011
byte c = -3;
if (~b > c)
{
a = c;
}
else
{
a = b;
}
但答案说是3
其解析为:
B is correct. "~" is the bitwise inverter. Hence the binary representation of ~b is "11111100" which is -4, thus the "else" condition gets executed and a gets the value of b which is 3.
就是不知道怎么会是负数了。