Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is arithmetic left shift of 01001001?

I would think it is 00010010 i.e. it tries to maintain the sign bit as is

On the other hand, the logical left shift by 1 pos would be 10010010

Is this correct?

like image 397
user855 Avatar asked Jan 10 '12 20:01

user855


1 Answers

For left shift, arithmetic and logical shift are the same.

The difference is for right shift only, where an arithmetic right shift will copy the old MSB to the new MSB after having shifted, thus keeping a negative number from being converted to a positive when shifting.

Wikipedia has a more detailed explanation.

like image 60
Anders Abel Avatar answered Oct 11 '22 05:10

Anders Abel