Skip navigation

Tag Archives: shift

This solution is for the book I am currently reading. All of my notes and solutions are available at Google Code.

Here is my work for problem 2.15:

Fill in the table below showing the effects of the different shift operations
on single-byte quantities. The best way to think about shift oeprations
is to work with binary representations. Convert the initial values to binary, 
perform shifts, and then convert back to hexadecimal. Each of the answers 
should be 8 binary digits or 2 hexadecimal digits.



-------------------------------------------------------------------------
       x                x << 2           x >> 2
                                        (Logical)       (Arithmetic)
-------------------------------------------------------------------------
  Hex     Binary    Hex     Binary    Hex     Binary    Hex     Binary
-------------------------------------------------------------------------
  0xF0
-------------------------------------------------------------------------
  0x0F
-------------------------------------------------------------------------
  0xCC
-------------------------------------------------------------------------
  0x55
-------------------------------------------------------------------------


0xF0

  0xF0
  11110000

  x << 2 (Logical)

  0x3C
  00111100

  x >> 2 (Arithmetic)

  0xFC
  11111100

0x0F

  0x0F
  00001111

  x << 2 (Logical)

  0x03
  00000011

  x >> 2 (Arithmetic)

  0x03
  00000011


0xCC

  0xCC
  11001100

  x << 2 (Logical)

  0x33
  00110011

  x >> 2 (Arithmetic)

  0xF3
  11110011

0x55

  0x55
  01010101

  x << 2 (Logical)

  0x15
  00010101

  x >> 2 (Arithmetic)

  0x15
  00010101

-------------------------------------------------------------------------
       x                x << 2           x >> 2
                                        (Logical)       (Arithmetic)
-------------------------------------------------------------------------
  Hex     Binary    Hex     Binary    Hex     Binary    Hex     Binary
-------------------------------------------------------------------------
  0xF0   11110000  0x80    10000000  0x3C    00111100  0xFC   11111100
-------------------------------------------------------------------------
  0x0F   00001111  0x78    01111000  0x03    00000011  0x03   00000011
-------------------------------------------------------------------------
  0xCC   11001100  0x60    01100000  0x33    00110011  0xF3   11110011
-------------------------------------------------------------------------
  0x55   01010101  0xA8    10101000  0x15    00010101  0x15   00010101
-------------------------------------------------------------------------