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,
. In binary, each digit is just a
bit, zero or one, and powers of two are used instead of powers of
ten. For example,
.
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
-bit unsigned
number can take on any value from
to
. 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
. 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).