Well, 1, in in binary is this:
00000000 00000000 00000000 00000001
So, if we want ~1, we flip all the bits:
11111111 11111111 11111111 11111110
As it turns out, that's the binary representation of -2. So, that explains the initial output of -2.
Next, we take that inverse and shift it to the right one position (using a signed shift). A signed right shift means that, whatever the sign bit is prior to the shift, that's what will get shifted in from the left. So, taking the above inserve and shifting to the right one position, we're left with this:
11111111 11111111 11111111 11111111
And that is the representation of -1, which explains the latter half of the output.
Here are some more articles you can read regarding bit operations and two's complement:
Negative Numbers in Java - Two's Complement Bit-Ops (AND, OR, XOR, NOT) Bit-Ops (Bit Shifting) Also, I believe bit operations, such as these, no longer appear on the 1.5 version of the exam, although they are a part of the 1.4 version.