+ 2
Signed right shift operator . Can anyone tell the below problem ?
8>>1 =4 it's ok -8>>1=-4 it's also ok but if I write -8>>-1 then output is -1 why ??
1 Resposta
+ 5
I'm guessing here, but it looks to me as you completely shift the bits out filling the result with the sign bit: -8>>-1 = -8>>63 = -1. Note that 8>>-1 = 8>>63 = 0.
I couldn't find anything in the Java docs to verify the issue.
If you truly want to left shift on negative, test for it and handle it.