I have been given the hexadecimal number 0xAA and been told to perform the following operations on it, in order:
Shift right by 3 And with 0x18 Shift left by 2
Here are my steps for doing this:
1.) Represent 0xAA in binary
0xAA = 1010 1010
2.) Shift right by 3
0001 0101
3.) Represent 0x18 in binary
0x18 = 0001 1000
4.) Perform 0001 0101 and 0001 1000
0001 0101 & 0001 1000 = 0001 0000
5.) Shift left by 2
0100 0000
And that is my final answer, 0100 0000. However, the answer I am told I should get is 0111. I cannot figure out where I am going wrong, or how I should get that answer. I was hoping someone could tell me where I am going wrong. Thank you all very much.
0111bif performing these operations:(0xAA >> 3 | 0x18) >> 2... maybe whoever told you0111bmeant to do that instead? You can't even get0111bif you sign-extend the0xAAin an 8-bit register or rotate instead of shift! (Also, you could never have anything that ends in11bafter left-shifting twice, so something is definitely up). - lungj