Originally posted by fraternity lawson:
public class rodney
{
public static void main(String[]args)
{
int b = -11; // 11111111 11111111 11111111 1111 0101
b = b >> 2; // 11111111 11111111 11111111 1111 1101 (2's complement of -3)
System.out.println(b);
}
}
How the output is coming -3.?
Your binary representation of -11 is not correct. It should be
1111 1111 1111 1111 1111 1111 1111 0110. What you have is just complement of 11. add 0001 to it and then it becomes -11.
After shifting two bits it becomes
1111 1111 1111 1111 1111 1111 1111 1101 which is -3