We need to concentrate on how computers represent numbers and
perform arithmetic. Suppose we have twenty-six "things." This
number is an abstract quantity that we need to represent so that
we can perform calculations on it. We represent this number
with positional notation using base 10:
26=2×101+6×100
26
21
60
. We could also use base-8 notation (
328=3×81+2×80
32
3
8
1
2
8
0
), base 16 (
1A16=1×161+A16×160
1A
1
16
1
A
16
0
, with A16A
representing ten), or base 2 (
110102=1×24+1×23+0×22+1×21+0×20
11010
1
2
4
1
2
3
0
2
2
1
2
1
0
2
0
). Each of these represent the same
quantity; all numbers can be so represented and arithmetic can
be performed in each system. Which we chose is a matter of
convenience and cultural heritage. Each position is occupied by
an integer between 0 and the base minus 1, and the integer's
position implicitly represents how many times the base raised to
an exponent is needed. The integer
N
N
is succinctly expressed in base-b as
Nb=
d
n
d
n
−
1
…
d
0
N
d
n
d
n
−
1
…
d
0
, which mathematically means
Nb=
d
n
bn+…+
d
0
b0
N
d
n
b
n
…
d
0
b
0
. No matter what base you might choose, addition, subtraction,
multiplication, and division all follow the same rules you
learned as a child. These rules can be derived mathematically
from the positional notation conventions defined by this
formula. (Non-positional systems are very strange; take Roman
numerals for example. Try adding (or, more extremely, dividing)
two numbers using this number representation system). To extend
the positional representation to signed integers, we add a
symbol that represents whether the number is positive or
negative.
Humans have ten fingers, and so it's not so surprising that many
cultures throughout history have used base 10. Digital
computers use base 2 or binary number
representation, each digit of which is known as a
bit (binary dig
it). 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 binary addition and multiplication tables are
0+0=0
0
0
0
(1)
1+1=10
1
1
10
0+1=1
0
1
1
1+0=1
1
0
1
0×0=0
0
0
0
0×1=0
0
1
0
1×1=1
1
1
1
1×0=0
1
0
0
A carry means that a computation performed at a
given position affects other positions as well. Here,
12+12=102
1
1
10
is an example of a computation that involves a carry. Note that
if carries are ignored, subtraction of two single-digit 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.
Add twenty-five and seven in base 2. Note the carries that
might occur. Why is the result "nice"?
25=110012
25
11001
and
7=1112
7
111
. We find that
110012+1112=1000002=32
11001
111
100000
32
.