Assignment 2, Solutions

Part of the homework for 22C:60 (CS:2630), Spring 2013
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

  1. Background: Once upon a time, some eccentric folks thought we ought to all learn the duodecimal system (Base 12). Perhaps it had to do with the fact that British currency used 12 pence per shilling or that eggs are traditionally sold by the dozen. The most common duodecimal representation augments the conventional decimal digits with A standing for 10 and B standing for 11. (each part of this problem is worth 0.1 points)

    A Problem: Convert each of the following duodecimal numbers to decimal:
    a) 100 = 1×122 = 144
    b) A9 = 1×12+9 = 21
    c) 234 = 2×122+3×12+4 = 288+36+4 = 328

    Another Problem: Convert each of the following decimal numbers to duodecimal:
    d) 100 = 96+4 = 8×12+4 = 84
    e) 512 = 432+72+8 = 4×122+6×12+8 = 468

  2. A Problem: Here are 5 random 8-bit unsigned binary numbers. Convert them to decimal. (0.1 points each)
    00010111 00010111 01111010 11011001 10101101
    
           1        1        2        1        1
           2        2        8        8        4
           4        4       16       16        8
        + 16     + 16       32       64       32
        ----     ----     + 64    + 128    + 128
          23       23     ----    -----    -----
                           122      217      173
    

    Two of the above were the same by random chance -- these numbers came from a hardware random number generator, and that sometimes happens, albeit with low probability.

  3. A Problem: Here are 5 random 8-bit two's complement binary numbers. Convert them to the usual signed-magnitude decimal number representation. (0.1 points each)
    11100100 01001110 11001010 11101111 01010110
    00011011          00110101 00010000
          +1        2                          2
    --------        4       +1       +1        4
    00011100        8        1     + 16       16
                 + 64        4     ----     + 64
           4     ----       16     - 17     ----
           8       78     + 32                86
        + 16              ----
        ----              - 54
        - 28
    

    Above, note that only the first, third and forth numbers are negative. The other two are positive, and can be converted as if they were unsigned. In the first conversion above, the one's complement was incremented in binary before conversion to decimal, while in the third and forth cases, the extra one was added in while converting the one's complement to decimal.

  4. A Problem: Here are 5 random 8-bit one's complement binary numbers. Convert them to the usual signed-magnitude decimal number representation. (0.1 points each)
    01101001 01011110 01001100 10001010 00100101
                               01110101
           1        2        4                 1
           8        4        8        1        4
          32        8     + 64        4     + 32
        + 64       16     ----       16     ----
        ----     + 64       76       32       37
                 ----              + 64
                   94              ----
                                  - 117
    

    Above, note that only the, forth number is negative. The others are positive, and can be converted as if they were unsigned.

  5. A Problem: Here are 5 random 8-bit binary numbers. Give their hexadecimal equivalents. We can't prevent you from using a calculator, but note that if you don't learn to do these kinds of problems in your head, the rest of the semester is likely to be extremely difficult. (0.1 points each)
    11010101 01010010 00110100 10010000 00000101
       D5       52       34       90       05
    

  6. Background: You find a word in the Hawk memory and convert its contents to decimal, getting this value: 3735928559.

    a) What is the decimal equivalent of each of the two halfwords that make up this word? Give them in order of ascending memory addresses. (0.2 points)

            11011110101011011011111011101111  converted to binary
    
            1101111010101101 1011111011101111 broken into 2 16-bit halfwords
    
                  57005            48879      converted to decimal
    
                  48879      placed in order by ascending address
                  57005
    

    b) What is the decimal equivalent of each of the four bytes that make up this word? Give them in order of ascending memory addresses. (0.3 points)

            11011110101011011011111011101111    converted to binary
    
            11011110 10101101 10111110 11101111 broken into 4 8-bit bytes
    
               222      173      190      239   converted to decimal
    
               239      placed in order by ascending address
               190
               173
               222
    

    (In this final problem, feel free to use calculators, on-line or off, but you will need to look at Chapter 3 first.)

(In this final problem, feel free to use calculators, on-line or off, but you will need to look at Chapter 3 first.)