Originally posted by Rohit Kharat:
Can you please tell me difference between >> and >>>
>>
op1 >> op2 Shifts bits of op1 right by distance op2; fills with highest (sign) bit on the left side
>>>
op1 >>> op2 Shifts bits of op1 right by distance op2; fills with 0 bits on the left side
What does the bold lettered line mean? "fills with highest (sign) bit"
Thx in advance.
Here, "fills with highest(sign) bit" refers to the most significant bit(MSB)(i.e. the left most bit). Both the >> and >>> yields the same result for positive numbers, since the MSB is 0. However, when they are applied to negative numbers, their behavior is completely different.
With >>, the sign bit(i.e. 1) is inserted at the MSB.
With >>>, a 0 is inserted at the MSB. So, most often, you always get a positive number.