CS350 Intro Computer Systems Homework 3

Homework 3 Integer and Floating Point Arithmetic

  1. For signed and unsigned multiplication, fill in the following table showing the results of multiplying different 5-bit numbers, in the style of Figure 2.27 of textbook (page 98) for w=5, by replacing "decimal" with decimal values and "binary" with binary values.
    Modexyx*y, w=10Truncated x*y, w=5
    (a)Unsigneddecimal10000decimal10101decimalbinarydecimalbinary
    Two's complementdecimal10000decimal10101decimalbinarydecimalbinary
    (b)Unsigneddecimal10101decimal01000decimalbinarydecimalbinary
    Two's complementdecimal10101decimal01000decimalbinarydecimalbinary
    (c)Unsigneddecimal01100decimal11001decimalbinarydecimalbinary
    Two's complementdecimal01100decimal11001decimalbinarydecimalbinary
    (d)Unsigneddecimal01010decimal00101decimalbinarydecimalbinary
    Two's complementdecimal01010decimal00101decimalbinarydecimalbinary
  2. Do problem 2.77.
  3. Write a C program to print the binary values of a floating point number passed as a parameter, as demonstrated in class, by filling in ftob.c. For example, it would print "0 01111110 10000000000000000000000" when you type "ftob 0.75." So would it "0 01111101 00110011001100110011010" when you type "ftob 0.3" as demonstrated in class.
  4. Round the following fractional values to the nearest quarter (2 bits to the right of the binary point), according to the round-to-even rule in the style of page 26 of Lecture note 4 (04-float.pdf).
    ValueBinaryRoundedActionRounded Value
    1 1/16
    1 3/16
    2 5/16
    2 5/8
    3 5/8
    3 7/8
  5. Convert the following decimal values to 9-bit floats, where bit 8 (the most signifincant bit) is the sign bit, bits 4-7 are exponents, and the rest (bits 0-3) are the significand. Follow the format of page 39 of Lecture note 4 (04-float.pdf).
    ValueRoundedExpAdjustedResult
    256
    31
    33
    35
    276
    127
  6. Write a C program to print the decimal value of a binary string passed as a parameter. For example, it would print 0.75 when you type "0 01111110 10000000000000000000000."
    As another example, it would print 0.125 when you type "0 01111100 00000000000000000000000."