How many r true :
1 ] An unsigned right shift >>> by a smaller positive amount (< total of bits of type) of a small negative number will result in a large positive number.
2 ] A mod (%) 16 is performed on the shift operand which affects shifts of more than 16 places for integers.
3 ] The signed right shift operation >> results in a number with the same sign bit.
4 ] The operators <<< and >>> are called bit-wise operators.
5 ] The operators << and >> are called shift operators.
Answer 2 is incorrect, It is mod 32 that returns the same value for integers. A mod 16 is applied for short values that will return the same value, the modulus of the size in bits of the type (integer, short, ..) is applied.
Answer 3 is correct. It is the left hand value of the operator that will be moved by the amount of positions specified in the right hand side operator. The sign bit of the first operand is shifted and replaced with its original value (so the sign is maintained).
2 >> 100 : This mean that the binary represantation of 2 will be moved to the right (closer to null) with 100 positions. The result for this example is 0.
-2 >> 100 : The result is -1. The right shift operation will not change the sign.
Answer 4 is incorrect, the operator <<< does not exists.
Answer 5 is correct they are called right shift operator (>>
and left shift operator (<<
.
Hi all ,
Answer 4 & 5 is clear to me but not others .
Please explain other 3 .
Thanks ,
ankur