Solution to exercise 2.11a (Part of Lab-01.)


Convert decimal 102 to its 8-bit 2's complement binary representation:


76543210
01100110
       102
      51
     50
     25
    24
    12
   6
  3
 1

102=a7*2^7 + a6*2^6 + a5*2^5 + a4*2^4 + a3*2^3 + a2*2^2 + a1*2^1 + a0*2^0

Because 102 is positive number, a7=0.
Because 102 is even number, a0=0.

102=         a6*2^6 + a5*2^5 + a4*2^4 + a3*2^3 + a2*2^2 + a1*2^1

A. Since 102 is even, we can divide both sides by 2:

 51=         a6*2^5 + a5*2^4 + a4*2^3 + a3*2^2 + a2*2^1 + a1*2^0

   Because 51 is odd, a1=1.

B. Decrement by 1 both sides:

 50=         a6*2^5 + a5*2^4 + a4*2^3 + a3*2^2 + a2*2^1

C. Since 50 is even, divide both sides by 2:

 25=         a6*2^4 + a5*2^3 + a4*2^2 + a3*2^1 + a2*2^0

D. Since 25 is odd, therefore a2=1

E. Subtract 1 and divide by 2:

 24=         a6*2^4 + a5*2^3 + a4*2^2 + a3*2^1
 12=         a6*2^3 + a5*2^2 + a4*2^1 + a3*2^0

F. Since 12 is even, therefore a3=0

 12=         a6*2^3 + a5*2^2 + a4*2^1
  6=         a6*2^2 + a5*2^1 + a4*2^0

F. Since 6 is even, therefore a4=0
   Divide by 2:

  3=         a6*2^1 + a5*2^0

G. Since 3 is odd, therefore a5=1
   Subtract 1 and divide by 2:

  2=         a6*2^1
  1=         a6*2^0

H. Since 1 is odd, therefore a6=1