Intelligentedu.com
Home
> Learn
About Computers, Software Development & Information Technology



By:
Don Johnson
Summary: Explains
how digital systems such as the computer represent numbers. Covers the
basics of boolean algebra and binary math.
To understand digital signal processing systems, we must understand a little about how computers compute. The modern definition of a computer is an electronic device that performs calculations on data, presenting the results to humans or other computers in a variety of (hopefully useful) ways.
Organization of a Simple
Computer

Computers
perform integer (discretevalued) computations.
Computer calculations can be numeric (obeying the laws of arithmetic),
logical (obeying the laws of an algebra), or symbolic (obeying any law
you like).1
Each computer instruction that performs an elementary numeric
calculation  an addition, a multiplication, or a division  does so
only for integers. The sum or product of two integers is also an
integer, but the quotient of two integers is likely to not be an
integer. How does a computer deal with numbers that have digits to the
right of the decimal point? This problem is addressed by using the
socalled floatingpoint
representation of real numbers. At its heart, however, this
representation relies on integervalued computations.
and we succinctly express $n$
in base$b$
as ${n}_{}$_{b}
All numbers can be represented by their sign, integer and fractional parts. Complex numbers can be thought of as two real numbers that obey special rules to manipulate them.
Number representations on computers

Here, each bit is
represented as a
voltage that is either "high" or "low," thereby representing "1" or
"0," respectively. To represent signed values, we tack on a special
bit—the sign
bit—to express the
sign. The computer's memory consists of an ordered sequence of bytes,
a collection of eight bits. A byte can therefore represent an unsigned
number ranging from $0$
to $255$.
If we take one of the bits and make it the sign bit, we can make the
same byte to represent numbers ranging from 127
to $127$.
But a computer cannot represent all
possible real numbers. The fault is not with the binary number system;
rather having only a finite number of bytes is the problem. While a
gigabyte of memory may seem to be a lot, it takes an infinite number of
bits to represent \pi.
Since we want to store many numbers in a computer's memory, we are
restricted to those that have a finite
binary representation. Large integers can be represented by an ordered
sequence of bytes. Common lengths, usually expressed in terms of the
number of bits, are 16, 32, and 64. Thus, an unsigned 32bit number can
represent integers ranging between 0
and \n{2}^{32}1\n(4,294,967,295),
a number almost big enough to enumerate every human in
the world!3
\left(\begin{array}{c}0+0=0\\ \mathrm{0+1}=1& \mathrm{1+1}=101+0=1\\ \\ \mathrm{0\times 0=0}0\times 1=0\\ \mathrm{1\times 1}=11\times 0=0& \begin{pmatrix}\\ ()\end{pmatrix}\end{array}\right)
Note that if carries are ignored,4 subtraction of two singledigit binary numbers yields the same bit as addition. Computers use high and low voltage values to express a bit, and an array of such voltages express numbers akin to positional notation. Logic circuits perform arithmetic operations.
Problem 1
Add twentyfive and seven in base 2. Note the carries that might occur. Why is the result "nice"?
Solution 1
${25}_{}$_{10}
We find that ${11001}_{}$_{2}
Also note that the logical operations of AND and OR are equivalent to binary addition (again if carries are ignored). The variables of logic indicate truth or falsehood. A ⋂B\n, the AND of $A$ and $B$, represents a statement that both $A$ and $B$ must be true for the statement to be true. You use this kind of statement to tell search engines that you want to restrict hits to cases where both of the events $A$ and $B$ occur. A⋂B, the OR of $A$ and $B$, yields a value of truth if either is true. Note that if we represent truth by a "1" and falsehood by a "0," binary multiplication corresponds to AND and addition (ignoring carries) to OR. The Irish mathematician George Boole discovered this equivalence in the midnineteenth century. It laid the foundation for what we now call Boolean algebra, which expresses as equations logical statements. More importantly, any computer using base2 representations and arithmetic can also easily evaluate logical statements. This fact makes an integerbased computational device much more powerful than might be apparent.
Computers express numbers in a fixedsize collection of bits, commonly known as the computer's word length. Today, wordlengths are either 32 or 64 bits, corresponding to a poweroftwo number of bytes (8bit "chunks"). This design choice restricts the largest integer (in magnitude) that can be represented on a computer.
Problem 2
For both 32bit and 64bit integer representations, what is the largest number that can be represented? Don't forget that the sign bit must also be included.
Solution 2
For $b$bit signed integers, the largest number is \n{2}^{b1}1. For $b=32$, we have 2,147,483,647 and for $b=64$, we have 9,223,372,036,854,775,807 or about $9.2\times {10}^{18}$.
While this system represents integers well, how about numbers having nonzero digits to the right of the decimal point? For such numbers, the binary representation system is used, but with a little more complexity. The floatingpoint system uses a number of bytes  typically 4 or 8  to represent the number, but with one byte (sometimes two bytes) reserved to represent the exponent $e$ of a poweroftwo multiplier for the number  the mantissa $m$  expressed by the remaining bytes.
The mantissa is usually taken to be a binary fraction having a
magnitude in the range \frac{\mathrm{[1}}{\mathrm{/2,}}1],
which means that the binary representation is such that ${d}_{}$_{1}
A computer's representation of integers is either perfect or only approximate, the latter situation occurring when the integer exceeds the range of numbers that a limited set of bytes can represent. Floating point representations have similar representation problems: if the number $x$ can be multiplied/divided by enough powers of two to yield a fraction lying between 1/2 and 1 that has a finite binaryfraction representation, the number is represented exactly in floating point. Otherwise, we can only represent the number approximately, not catastrophically in error as with integers. For example, the number 2.5 equals $0.625\times {2}^{2}$, the fractional part of which has an exact binary representation. 6 However, the number $2.6$ does not have an exact binary representation, and only be represented approximately in floating point. In single precision floating point numbers, which require 32 bits (one byte for the exponent and the remaining 24 bits for the mantissa), the number 2.6 will be represented as $\mathrm{2.600000079...}$. Note that this approximation has a much longer decimal expansion. This level of accuracy may not suffice in numerical calculations. Double precision floating point numbers consume 8 bytes, and quadruple precision 16 bytes. The more bits used in the mantissa, the greater the accuracy. This increasing accuracy means that more numbers can be represented exactly, but there are always some that cannot. Such inexact numbers have an infinite binary representation. 7 Realizing that real numbers can be only represented approximately is quite important, and underlies the entire field of numerical analysis, which seeks to predict the numerical accuracy of any computation.
Problem 3
What are the largest and smallest numbers that can be represented in 32bit floating point? in 64bit floating point that has sixteen bits allocated to the exponent? Note that both exponent and mantissa require a sign bit.
Solution 3
In floating point, the number of bits in the exponent determines the largest and smallest representable numbers. For 32bit floating point, the largest (smallest) numbers are ${2}^{\pm 127}=1.7\times {10}^{38}$ ($5.9\times {10}^{39}$). For 64bit floating point, the largest number is about ${10}^{9863.}$
So long as the integers aren't too large, they can be represented exactly in a computer using the binary positional notation. Electronic circuits that make up the physical computer can add and subtract integers without error.8
Footnotes
1. An example of a symbolic computation is sorting a list of names.
3. You need one more bit to do that.
5. In some computers, this normalization is taken to an extreme: the leading binary digit is not explicitly expressed, providing an extra bit to represent the mantissa a little more accurately. This convention is known as the hiddenones notation.
6. See if you can find this representation.
7. Note that there will always be numbers that have an infinite representation in any chosen positional system. The choice of base defines which do and which don't. If you were thinking that base 10 numbers would solve this inaccuracy, note that $1/3=\mathrm{0.333333....}$has an infinite representation in decimal (and binary for that matter), but has finite representation in base 3.
8. This statement isn't quite true; when does addition cause problems?
License
This work is licensed by