I am currently studying assembly, and with it the workings of bitwise operations amongst them shifting. Specifically arithmetic rightshifting is bothering me.
Now, in the book i am reading there are several practice problems, amongst them, I need to perform this operation on a byte consisting of:
0100 0100
Now, seeing as the arithmetic rightshift fills in the value of the most significant bit, it seems to me this should be right shited like so:
00001000
However, the book states that it should be
11101000
That is, 1's are filled in from the left instead of 0's. But wasn't the most significant bit a 0?
well, there's another as well:
0110 0100 >> 3 = 0000 1100
But, apparently that's wrong as well, and it should be:
11101100
Again, I don't get it the most significan't bit value is clearly 0, the one the furthest to the left, yet the solution tells me 1's should be filled in?
so i have a final one here that apparently is correct:
0111 0010 >> 3 = 0000 1110
This is what I would expect. So why aren't these others correct?
Reading assembly is incredibly hard without understanding this, since a lot of multiplication and division is compiled to shift operations.
0100 0100
is positive in 1's complement as well. Yes, it should shift in zeros to produce a result with the same sign as the initial value. – Peter Cordes