Page 409 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 409

386                   Appendix 1 Number Representations and Binary Arithmetic


        PROBLEMS

         1. Find the hexadecimal equivalents of the 8-bit two's-complement representations of
        -44 and-121.

        2. Explain why the 16's-complement technique works when used for calculations such as
        Problem 1.

        3. Suppose that you were going to add a 16-bit two's-complement representation with an
        8-bit one. How would you change the 8-bit representation so that the 16-bit result would
        be correct? This process is sometimes called sign extension.

        4. Give a simple condition for signed overflow when two's-complement representations
        are subtracted,

        5. One textbook reason for preferring the two's-complement representation of integers
        over the signed-magnitude representation is that the logic design of a device that adds and
        subtracts numbers is simpler. For example, suppose that M and N have m-bit two's-
        complement representations x and y. To subtract M from N, one can take the two's-
        complement of x and then add it to y, presumably simpler from the logic design
        viewpoint than dealing with signed-magnitudes. Does this always work? Try it with m =
        8 N equal to -1, and M equal to -128. What is the condition for overflow? Does this
        work when N and M are interpreted as unsigned numbers? Interpret.

        6. Suppose that we add two m-bit representations x and y, where x is the unsigned
        representation of M and y is the two's-complement representation of N. Will the answer,
        truncated to m bits, be correct in any sense? Explain.
   404   405   406   407   408   409   410   411   412   413   414