posted 22 years ago
Mock Exam Question:
After execution of the following code, what is the value of a?
byte b = 3; //binary 00000011
byte c = -3;
if (~b > c)
{
a = c;
}
else
{
a = b;
}
a. -3
b. 3
c. 0
d. none of the above.
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.
My question is, why is 11111100 -4 instead of 252?