Exercise 1 ========== #. An :math:`\mathsf{N}`-bit binary register can hold :math:`\mathsf{2^N}` unique bit patterns. To represent an unsigned integer, the bit patterns are interpreted as the base-2 numbers 0 to :math:`\mathsf{2^N-1}`. There are several possible ways to represent signed integers. Nonetheless, on all modern computers this is accomplished using the *two's complement* scheme (we'll denote it as base :math:`\mathsf{\bar{2}}`), in which the the numbers :math:`\mathsf{-2^{N-1}}` to :math:`\mathsf{+2^{N-1}-1}` are represented by the same bit patterns reinterpreted as :math:`\mathsf{0}` to :math:`\mathsf{2^{N-1}-1}` and then :math:`\mathsf{-2^{N-1}}` to :math:`\mathsf{-1}` in lexical order. The table below illustrates the unsigned (left) and signed (right) values for :math:`\mathsf{N=8}`: .. list-table:: * - 127 - 0 1 1 1 1 1 1 1 - 127 * - 126 - 0 1 1 1 1 1 1 0 - 126 * - 2 - 0 0 0 0 0 0 1 0 - 2 * - 1 - 0 0 0 0 0 0 0 1 - 1 * - 0 - 0 0 0 0 0 0 0 0 - 0 * - 255 - 1 1 1 1 1 1 1 1 - −1 * - 254 - 1 1 1 1 1 1 1 0 - −2 * - 253 - 1 1 1 1 1 1 0 1 - −3 * - 129 - 1 0 0 0 0 0 0 1 - −127 * - 128 - 1 0 0 0 0 0 0 0 - −128 a. The advantage of two's complement numbers is that they can be added, in the mechanistic sense, exactly the same way as conventional binary numbers: .. math:: \begin{aligned} &\texttt{\phantom{0}\phantom{0}{\color{red}1}{\color{red}1}\phantom{0}\phantom{0}{\color{red}1}} \\ &\texttt{01011001} \\ +&\texttt{10011101} \\ \hline &\texttt{11110110} \end{aligned} Here, red ones represent the carry bits. Explain the two ways the computation above can be interpreted---as either unsigned binary or two's complement. b. Determine the 8-bit unsigned binary representation of 116. Does the two's complement representation of that number have the same bit pattern? c. In the :math:`\mathsf{N}`-bit two's complement scheme, negation (i.e., mapping a number :math:`x \to -x`) is accomplished by all flipping all :math:`N` bits and then adding one (modulo :math:`2^N`, of course). Negate the 8-bit two's complement number :math:`116` from part b. d. One advantage of two's complement is that it encodes a unique zero (rather than both :math:`0` and :math:`-0`). But there is one nonzero value that also behaves as :math:`x \to x` under negation. What is it? e. There are four possible values for the two leftmost carry bits (marked with dots): 00, 01, 10, 11. Which combinations denote an overflow for unsigned binary and which for signed (two's complement) binary? #. Change the octal numbers :math:`\mathsf{60177756_8}`, :math:`\mathsf{3006012_8}`, :math:`\mathsf{3726755_8}`, :math:`\mathsf{76545336_8}`, :math:`\mathsf{5655_8}`, and :math:`\mathsf{67545336_8}` to hexadecimal notation using the digits :math:`\mathsf{0,1,\ldots,F}`. *Hint:* Doing this by hand is easiest if you use the base-2 bit patterns as an intermediate step. #. We can generalize a positional number system to negative bases by writing .. math:: \mathsf{(\cdots a_3a_2a_1a_0.a_{-1}a_{-2}\cdots)_{b} = \cdots + a_2b^2 + a_1 b + a_0 + a_{-1}b^{-1} + \cdots} in the usual way but requiring that the digits be in the range :math:`0 \le a_k < | b |`. For example, .. math:: \begin{aligned} \mathsf{1322_{-4}} &= \mathsf{-22}\\ \mathsf{133.21_{-5}} &= \mathsf{12.64}\\ \mathsf{2050.23_{-6}} &= \mathsf{-462.25}\\ \mathsf{6231.46_{-8}} &= \mathsf{-2967.40625} \end{aligned} a. Negate each of the identities above. b. Is there a unique negative base representation for each number? c. Is it ever necessary to have a leading minus sign, e.g., :math:`\mathsf{-54_{-3}}`, when the base is negative? #. Consider a 6-digit *factoradic* system .. math:: \mathsf{(a_6 \ldots a_3a_2a_1) = a_6\cdot 6! + \cdots + a_3\cdot 3! + a_2 \cdot 2! + a_1, \quad \textsf{where}\ 0 \le a_k \le k} a. What are the largest and smallest numbers representable? b. Is every number in between representable?