This preview shows pages 1–3. Sign up to view the full content.
CSCI 120 Introduction to Computation
It’s only a matter of representation (cont.) (draft)
Saad Mneimneh
Visiting Professor
Hunter College of CUNY
1 What about negative numbers?
People confronted the problem or representing negative numbers even before
the ﬁrst electronic computer. After all, negative numbers existed long time
ago. Before we address this issue, let’s see how many (positive) numbers can we
represent with
n
bits. To answer this question, it is enough to determine the
largest possible number, since we know that the smallest is zero. Let’s transpose
this back to the decimal system since we are much more familiar with it. What
is the largest number that we can represent with
n
decimal digits? Well, it is
999.
..9 (
n
times). Therefore, the largest number is 10
n

1. For instance, with 3
decimal digits, the largest number we can represent is 10
3

1 = 999. The same
rule applies for the binary system. The largest number we can represent with
n
bits is 2
n

1. For instance, with 4 bits, the largest number that we can represent
is 2
4

1 = 15. Therefore, we have a total of 16 (positive) numbers (including 0).
0
0000
1
0001
2
0010
3
0011
4
0100
5
0101
6
0110
7
0111
8
1000
9
1001
10
1010
11
1011
12
1100
13
1101
14
1110
15
1111
In general, we have a total of 2
n
numbers, and they are all positive ranging
from 0 to 2
n

1. Current machines use
n
= 32 or even
n
= 64 bits (so that’s a
huge number).
One way of introducing negative numbers is by using one of the bits (usu
ally the leftmost bit) as a sign bit. This seems natural because this is how we
represent negative numbers on paper. We simply put a sign to the left of the
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Documentnumber. Therefore, in an
n
bit computer, the leftmost bit (also called most
signiﬁcant bit) would be the sign bit followed by the
n

1 bit number. We end
up with the range [0
...
2
n

1

1] for positive numbers and [

(2
n

1

1)
...
0] for
negative numbers. This technique is called signed magnitude. Note that zero
has two representations now, minus zero and positive zero. For
n
= 4 bits, this
is what we get:
0
0000
1
0001
2
0010
3
0011
4
0100
5
0101
6
0110
7
0111
0
1000
1
1001
2
1010
3
1011
4
1100
5
1101
6
1110
7
1111
Basically, each number is interpreted as a sign bit followed by the represen
tation of an
n

1 bit number. So 1101 is (101) and 101 in binary is 5, so 1101
is a representation of 5.
Although this seems natural to us, it is not natural to computers at all.
Consider for instance when the computer adds two numbers. First it has to
look at the signs of both numbers, then decide, based upon the signs, whether
to add them or subtract one from the other, and what sign the result will have.
Wouldn’t it be nice if the computer’s arithmetic unit never needed to know if a
number is positive or negative and simply added any two numbers and still got
the correct result? This turns out to be possible indeed.
2 One’s complement
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '09
 SaadMneimneh

Click to edit the document details