0
votes

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.

1
I apologize for the formatting in my post, the operations I must perform are: 1.) Shift right by three 2.) And with 0x18 3.) Shift left by 2 - E. Johnson
If this are all the given information: Your result is right. - Joshua K
Your answer looks right to me for the given steps. However, I get 0111b if performing these operations: (0xAA >> 3 | 0x18) >> 2... maybe whoever told you 0111b meant to do that instead? You can't even get 0111b if you sign-extend the 0xAA in an 8-bit register or rotate instead of shift! (Also, you could never have anything that ends in 11b after left-shifting twice, so something is definitely up). - lungj
This is all the given information, thank you Joshua, I appreciate your help - E. Johnson
lungi, if I am understanding correctly, you get 0111 if you shift right by 2 instead of left by 2 at the last step. My understanding would lead me to believe that these steps would result in 0100, why do you fill in ones to the right? - E. Johnson

1 Answers

0
votes

It seems that I am calculating the correct result, and it is the expected result that is incorrect. Thank you all for your help.