|
| 1 | +\model{Negative Numbers} |
| 2 | + |
| 3 | + \quest{15 min} |
| 4 | + |
| 5 | + \Q Consider a traditional analog clock face. |
| 6 | + \vspace{10pt} |
| 7 | + \begin{center} |
| 8 | + \includegraphics[width=0.25\textwidth]{figures/clock.png} |
| 9 | + \end{center} |
| 10 | + |
| 11 | + \begin{enumerate} |
| 12 | + \item How many unique hours can it represent? |
| 13 | + \hfill\ans{12} |
| 14 | + |
| 15 | + \item What is the range of hours it represents? |
| 16 | + \hfill\ans{1 to 12} |
| 17 | + |
| 18 | + \item If we think of 3:00 as ``three hours after noon'' (or ``+3''), what hour position on the clock is represented by ``three hours before noon'' (``-3'')? |
| 19 | + \begin{answer}[0.5in] |
| 20 | + 9 |
| 21 | + \end{answer} |
| 22 | + |
| 23 | + \item What range of integers would support the same number of negative clock-face ``hours'' as nonnegative clock-face ``hours''? |
| 24 | + \begin{answer}[0.5in] |
| 25 | + -6 to +5 |
| 26 | + \end{answer} |
| 27 | + \end{enumerate} |
| 28 | + |
| 29 | + \vspace{-20pt} |
| 30 | + |
| 31 | + \Q Complete the following table to map the typical clock face hours (line 1) to the hours before and after noon (line 2). |
| 32 | + (Hint: start at each end and work to the middle.) |
| 33 | + \vspace{10pt} |
| 34 | + \begin{center} |
| 35 | + \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|} |
| 36 | + \hline |
| 37 | + 12 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \\ |
| 38 | + \hline |
| 39 | + \ans[0.3in]{0} & \ans[0.3in]{1} & \ans[0.3in]{2} & \ans[0.3in]{3} & \ans[0.3in]{4} & \ans[0.3in]{5} & \ans[0.3in]{-6} & \ans[0.3in]{-5} & \ans[0.3in]{-4} & \ans[0.3in]{-3} & \ans[0.3in]{-2} & \ans[0.3in]{-1} \\ |
| 40 | + \hline |
| 41 | + \end{tabular} |
| 42 | + \end{center} |
| 43 | + |
| 44 | + \Q With this relabeled clock, answer the following questions: |
| 45 | + \begin{enumerate} |
| 46 | + \item If we start at 2 and add 2, what do we get? |
| 47 | + \hfill\ans{+4} |
| 48 | + |
| 49 | + \item If we start at 2 and subtract 1, what do we get? |
| 50 | + \hfill\ans{+1} |
| 51 | + |
| 52 | + \item If we start at 2 and subtract 2, what do we get? (Hint: not 12) |
| 53 | + \hfill\ans[1.5in]{0} |
| 54 | + |
| 55 | + \item If we start at 2 and subtract 5, what do we get? |
| 56 | + \hfill\ans{-3} |
| 57 | + |
| 58 | + \item If we start at -2 and subtract 2, what do we get? |
| 59 | + \hfill\ans{-4} |
| 60 | + |
| 61 | + \item If we start at -2 and add 6, what do we get? |
| 62 | + \hfill\ans{+4} |
| 63 | + |
| 64 | + \item So far this maps very nicely to ``normal'' arithmetic. But if we start at 5 and add 3, what do we get? (Hint: not 8!) |
| 65 | + \begin{answer}[0.5in] |
| 66 | + -4 |
| 67 | + \end{answer} |
| 68 | + |
| 69 | + \item If we start at -5 and subtract 4, what do we get? (Hint: not -9!) |
| 70 | + \hfill\ans[1.5in]{+3} |
| 71 | + \end{enumerate} |
| 72 | + |
| 73 | + \Q Using a similar approach, fill in the following table to map selected unsigned values [0, 255] to signed values [-128, 127]. This is called a two's complement. |
| 74 | + \vspace{10pt} |
| 75 | + \begin{center} |
| 76 | + \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|} |
| 77 | + \hline |
| 78 | + 0 & 1 & 2 & \ldots & 126 & 127 & 128 & 129 & 130 & \ldots & 254 & 255 \\ |
| 79 | + \hline |
| 80 | + \ans[0.2in]{0} & \ans[0.2in]{1} & \ans[0.2in]{2} & \ldots & \ans[0.25in]{126} & \ans[0.25in]{127} & \ans[0.3in]{-128} & \ans[0.3in]{-127} & \ans[0.3in]{-126} & \ldots & \ans[0.2in]{-2} & \ans[0.2in]{-1} \\ |
| 81 | + \hline |
| 82 | + \end{tabular} |
| 83 | + \end{center} |
| 84 | + |
| 85 | + \Q Convert some of these binary values to unsigned and signed decimal:\key\\[-2.5mm] |
| 86 | + \vspace{10pt} |
| 87 | + \begin{center} |
| 88 | + \begin{tabular}{|c|c|c|} |
| 89 | + \hline |
| 90 | + \textbf{Binary} & \textbf{Unsigned Decimal} & \textbf{Signed Decimal} \\ |
| 91 | + \hline |
| 92 | + 0000 0000 & \ans[0.4in]{0} & \ans[0.4in]{0} \\ |
| 93 | + \hline |
| 94 | + 0000 0001 & \ans[0.4in]{1} & \ans[0.4in]{1} \\ |
| 95 | + \hline |
| 96 | + 0111 1110 & \ans[0.4in]{126} & \ans[0.4in]{126} \\ |
| 97 | + \hline |
| 98 | + 0111 1111 & \ans[0.4in]{127} & \ans[0.4in]{127} \\ |
| 99 | + \hline |
| 100 | + 1000 0000 & \ans[0.4in]{128} & \ans[0.4in]{-128} \\ |
| 101 | + \hline |
| 102 | + 1000 0001 & \ans[0.4in]{129} & \ans[0.4in]{-127} \\ |
| 103 | + \hline |
| 104 | + 1111 1110 & \ans[0.4in]{254} & \ans[0.4in]{-2} \\ |
| 105 | + \hline |
| 106 | + 1111 1111 & \ans[0.4in]{255} & \ans[0.4in]{-1} \\ |
| 107 | + \hline |
| 108 | + \end{tabular} |
| 109 | + \end{center} |
| 110 | + |
| 111 | + \Q How does the high-order (left-most) bit correlate with the sign? |
| 112 | + \hfill\ans[1.5in]{0 $\Rightarrow$ positive; 1 $\Rightarrow$ negative} |
| 113 | + |
| 114 | + \newpage |
| 115 | + |
| 116 | + \Q Perform some addition of signed binary numbers and note how the sign works: |
| 117 | + \vspace{10pt} |
| 118 | + \begin{center} |
| 119 | + \begin{tabular}{|c|c|c|c|} |
| 120 | + \hline |
| 121 | + 11 & 0000 1011 & -118 & 1000 1010 \\ |
| 122 | + + 5 & + 0000 0101 & + 44 & + 0010 1100 \\ |
| 123 | + \hline |
| 124 | + \ans[1in]{16} & \ans[1in]{0001 0000} & \ans[1in]{-74} & \ans[1in]{1011 0110} \\ |
| 125 | + \hline |
| 126 | + 106 & 0110 1010 & -22 & 1110 1010 \\ |
| 127 | + + -63 & + 1100 0001 & + -86 & +1010 1010 \\ |
| 128 | + \hline |
| 129 | + \ans[1in]{43} & \ans[1in]{1 0010 1011} & \ans[1in]{-204} & \ans[1in]{1 1001 0100} \\ |
| 130 | + \hline |
| 131 | + \end{tabular} |
| 132 | + \end{center} |
| 133 | + |
| 134 | + This suggests that another way to do subtraction is just to add the negative value. So how do we get a negative? Compare a few examples and |
| 135 | + note that in each case, if you added the values you would get zeros in the right-most (low order) 8 bits (which is, of course, correct). |
| 136 | + |
| 137 | + \vspace{10pt} |
| 138 | + \begin{center} |
| 139 | + \begin{tabular}{ccc} |
| 140 | + 1 = 0000 0001 & & -1 = 1111 1111 \\ |
| 141 | + 2 = 0000 0010 & & -2 = 1111 1110 \\ |
| 142 | + 126 = 0111 1110 & & -126 = 1000 0010 \\ |
| 143 | + 127 = 0111 1111 & & -127 = 1000 0001 \\ |
| 144 | + \end{tabular} |
| 145 | + \end{center} |
| 146 | + |
| 147 | + \Q For each positive value above (1, 2, 126, and 127), write out its one's complement or inverse (replace 0 with 1, 1 with 0). |
| 148 | + \vspace{10pt} |
| 149 | + \begin{center} |
| 150 | + \begin{tabular}{cccc} |
| 151 | + \ans[1in]{1111 1110} & \ans[1in]{1111 1101} & \ans[1in]{1000 0001} & \ans[1in]{1000 0000} \\ |
| 152 | + \end{tabular} |
| 153 | + \end{center} |
| 154 | + |
| 155 | + \vspace{-20pt} |
| 156 | + |
| 157 | + \Q How does the inverse compare with the negative value? What would you add\key\\[-2.5mm] to the inverse to get the negative? Learn this useful rule for computing the negative of a number! |
| 158 | + \begin{answer}[0.5in] |
| 159 | + The inverse is one less than the negative. To get a negative, invert and add 1. |
| 160 | + \end{answer} |
0 commit comments