Apparently D and F are both equivalent. I am familiar with the >> operator but I am not familiar with the >>> operator. What does it do? From my experimentation, they are exactly equivalent.
Try it with negative numbers.
Originally posted by Raef Kandeel:
but I am not familiar with the >>> operator. What does it do? From my experimentation, they are exactly equivalent.
with >> shift operator the bits are moved to right by the number which you mentioned and the left most bit would be added by zero's.
But >>> shift operator works the same for positive values but for negative values the left most bits would be replaced by 1's and not zero's
sorry i cannot explain with example as i dont have material right now, but i am sure about the concept that >>> shift operator on a negative numbers shifts the bits as requested and the left most bits would be filled by 1's instead of 0'2.
i will just try and find a link for you give 5 min
Unsigned right-shift >>> (JLS �15.19)
identical to the right-shift operator only the left-bits are zero filled
because the left-operand high-order bit is not retained, the sign value can change
if the left-hand operand is positive, the result is the same as a right-shift
if the left-hand operand is negative, the result is equivalent to the left-hand operand right-shifted by the number indicated by the right-hand operand plus two left-shifted by the inverted value of the right-hand operand
For example: -16 >>> 2 = (-16 >> 2 ) + ( 2 << ~2 ) = 1,073,741,820
Decimal 16 00000000000000000000000000010000
Right-shift 2 00000000000000000000000000010000
fill left 00000000000000000000000000000100
discard right 00000000000000000000000000000100 -> Decimal 4
Decimal -16 11111111111111111111111111110000
>>> 2 11111111111111111111111111110000
fill left 0011111111111111111111111111110000
discard right 00111111111111111111111111111100
its clearly explained here
hope i solved your problem
hope it did help your problem
Didn't I read somewhere that shifting operators are not on the exam ?
Originally posted by Dave Walsh:
..,Didn't I read somewhere that shifting operators are not on the exam ?
They are on the 1.4 exam, but not on the 1.5 exam.
16>>2 = 4 moving bit right decreases power of 2
here 2^4 =16 and right shift by 2 means 2^2 =4
16/2^2 = 4
Not correct, since '^' is the XOR operator.
Originally posted by Ameen khan:
16/2^2 = 4