I am having a difficult time wrapping my head around negative unsigned bitwise operators. For example, I have the code below. It prints out the value 7 and I don't understand why.
int num1 = -37, num2 = -3;
System.out.println( num1 >>> num2);
// Essentially the same as System.out.println( -37 >>> -3);
// I just wanted to emphasize that i am working with Integers
From my knowledge, the number -37 in binary format is as shown below.
11111111 11111111 11111111 11011010 = -37 (in decimal format)
If we are unsigned right shift of 3 ( -37 >>> 3, not -37 >>> -3), from my knowledge (please correct me if my theory is flawed or lacking key concepts), it shifts the bytes to the right by 3 and the 3 bits that fall out on the right most position appear on the left most position in a flipped down state (from zero to one), meaning that we get the following result.
00011111 11111111 11111111 11111011 = 536870907 (in decimal format).
However, if we apply an unsigned right shift of -3 ( -37 >>> -3), we get the result 7. I don't understand why it is returning 7. Could somebody please explain it to me?