I read somewhere that >>> operator always results in a positive number. Is it statement true or false. I think it is true but answer was given as false. Maybe the exam creator had in mind if a negative number is >>> by 0 then asnwer will be negative?
Hi After the >>> operation if the result is assigned to int variable it results in positive value.But if the result needs to be casted to byte/short it may result in negative value. correct me if i am wrong. Regards jaya s k
hi: You are right. After the >>> operator x times, the leading x bits is 0s(the left most bits). However, if you cast it to lower number of bits, it might result in a negative number. here is an example: 00000000 00000000 00000011 11111111 // int x = 1023 1- x >>> 2 = 255 // 00000000 00000000 00000000 11111111 2- byte y = (byte) x; // 11111111 In statement 2, we trimmed the int to a byte, which result in a negative number.
SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
I believe Manu is onto the point of the question. The shift operators do nothing if the amount to shift is a multiple of 32 in the case of shifting an int, or 64 in the case of a long. This creates the exception to the always-positive rule for >>>.
The Inner that is named is not the true Inner.
Catch Ernie! Catch the egg! And catch this tiny ad too: