Search code examples
operatorsbitwise-operatorsbit-shift

Question on arithmetic right shift operator


I am having a little trouble wrapping my head around this particular operation-
0x44 >> 3
Where >> is an arithmetic right shift operator.
Now, the textbook which I'm referring to gives the answer as 1110 1000
However, I did it as follows-
0x44 => 0100 0100
Now, since the first bit is a zero, I calculated the result of arithmetic right shift as 0000 1000 (hex value 0x08)
But, the book gives the answer as 1110 1000 (hex value 0xE9)
What am I doing wrong here? (The book is CS:APP, practise problem 2.16 for those interested).


Solution

  • As far as I can tell, this is practice problem 2.16 from the global edition of Computer Science: A Programmer's Perspective (3rd edition), which according to the original authors is full of errors.

    Direct quote from the errata page:

    Note on the Global Edition: Unfortunately, the publisher arranged for the generation of a different set of practice and homework problems in the global edition. The person doing this didn't do a very good job, and so these problems and their solutions have many errors. We have not created an errata for this edition.

    The advice around the web seems to be to pick up the North American edition if you're interested in doing the practice and homework problems.

    Your answer is indeed the correct one:

    0x44 >> 3 == 0x08