Exercise 1
An \(\mathsf{N}\)-bit binary register can hold \(\mathsf{2^N}\) unique bit patterns. To represent an unsigned integer, the bit patterns are interpreted as the base-2 numbers 0 to \(\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 \(\mathsf{\bar{2}}\)), in which the the numbers \(\mathsf{-2^{N-1}}\) to \(\mathsf{+2^{N-1}-1}\) are represented by the same bit patterns reinterpreted as \(\mathsf{0}\) to \(\mathsf{2^{N-1}-1}\) and then \(\mathsf{-2^{N-1}}\) to \(\mathsf{-1}\) in lexical order.
The table below illustrates the unsigned (left) and signed (right) values for \(\mathsf{N=8}\):
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
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:
\[\begin{aligned} &\texttt{{\color{red}*}{\color{red}*}\phantom{0}{\color{red}1}{\color{red}1}\phantom{0}\phantom{0}{\color{red}1}} \\ &\phantom{\texttt{+}}\texttt{01011001} \\ &\texttt{+10011101} \\ \hline &\phantom{\texttt{+}}\texttt{11110110} \end{aligned}\]Here, red ones represent the activated carry bits. The red asterisks just mark the position of the leftmost two carry bits, which in this calculation are both off.
Explain the two ways the computation above can be interpreted—as either unsigned binary or two’s complement.
Determine the 8-bit unsigned binary representation of 116. Does the two’s complement representation of that number have the same bit pattern?
In the \(\mathsf{N}\)-bit two’s complement scheme, negation (i.e., mapping a number \(\mathsf{x} \to -\mathsf{x}\)) is accomplished by all flipping all \(\mathsf{N}\) bits and then adding one (modulo \(\mathsf{2^N}\), of course). Negate the 8-bit two’s complement number \(116\) from part b.
One advantage of two’s complement is that it encodes a unique zero (rather than both \(0\) and \(-0\)). But there is one nonzero value that also behaves as \(x \to x\) under negation. What is it?
There are four possible values for the leftmost two carry bits (marked with red asterisks): 00, 01, 10, 11. Which combinations denote an overflow for unsigned binary and which for signed (two’s complement) binary?
Change the octal numbers \(\mathsf{60177756_8}\), \(\mathsf{3006012_8}\), \(\mathsf{3726755_8}\), \(\mathsf{76545336_8}\), \(\mathsf{5655_8}\), and \(\mathsf{67545336_8}\) to hexadecimal notation using the digits \(\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
\[\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 \(0 \le \mathsf{a}_\mathsf{k} < | \mathsf{b} |\). For example,
\[\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}\]Negate each of the identities above.
Is there a unique negative base representation for each number?
Is it ever necessary to have a leading minus sign, e.g., \(\mathsf{-54_{-3}}\), when the base is negative?
Consider a 6-digit factoradic system
\[\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}\]What are the largest and smallest numbers representable?
Is every number in between representable?