next up previous
Next: Comparison of Integers Up: Integer Representation and Arithmetic Previous: Integer Representation and Arithmetic

Unsigned Integers

We represent unsigned binary numbers in a fashion similar to traditional decimal numbers. In decimal, each digit starting from the right is multiplied by successive powers of ten. For example, $6562=6*10^3+5*10^2+6*10^1+2*10^0$. In binary, each digit is just a bit, zero or one, and powers of two are used instead of powers of ten. For example, $10101001=1*2^7+0*2^6+1*2^5+0*2^4+1*2^3+0*2^2+0*2^1+1*2^0$.

\begin{eqnarray*}
\mathit{value}(b_{n-1} b_{n-2} \ldots b_1 b_0) & = & b_{n-1} *
2^{n-1} + b_{n-2} * 2^{n-2} + \ldots + b_1 * 2^1 + b_0 * 2^0 \\
\end{eqnarray*}



Conceptually, any such number has an infinite number of zeros to the left (the higher powers of two), but we generally limit ourselves to some finite number of bits, such as 8 or 32. An $n$-bit unsigned number can take on any value from $0$ to $2^n-1$. Because of this finite range, we will sometimes try to create numbers that are too large to be represented with the given number of bits. This problem is called overflow and a processor may react to it in various ways. When overflow is ignored, it is convenient to think of it as operating module $2^n$. In the languages C and C++, overflow is always ignored.

Conversion between different sizes of unsigned integers is fairly trivial. When increasing the size, the existing bits are copied and the higher order bits are made zero. When decreasing the size, the lower order bits that fit are copied and the remaining bits are ignored (if they are non-zero, the value of the integer changes).


next up previous
Next: Comparison of Integers Up: Integer Representation and Arithmetic Previous: Integer Representation and Arithmetic
Jeffrey Considine 2001-05-01