0% found this document useful (0 votes)
6 views14 pages

Number Systems 2

Uploaded by

arfaali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views14 pages

Number Systems 2

Uploaded by

arfaali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

NUMBER SYSTEMS

2. Negative Numbers and Subtraction


J.N. Coleman
Obviously, a computer needs to add and
subtract, and to represent -ve numbers.
Subtraction has a different table from
addition:
+ 0 1 - 0 1
0 0 1 0 0 1
1 1 10 1 11 0
carry borrow

However, having two sets of circuits is not


economical, so we use a different
method.
Imagine the mileometer on a new car:

000000
It drives 1 mile forwards:

000001

Then 2 miles backwards:

999999

So -1 is represented as 999999.
This is 10’s complement representation.
Don’t want separate add and subtract
circuits.
If negative numbers are represented as
complements, subtraction isn’t needed.
-1 999999
+ +2 + 000002
+1 000001
Normal method: even though Using complement: the
the operation is +, one value is operation is +, and it’s done by
-ve, so would normally have to addition
subtract
To subtract a number, take its
complement and add it:

+2 000002
- +1 + 999999
+1 000001
Both values are +ve, but we’re Using a complement, the subtraction
subtracting them so, again, would is instead done by addition
normally have to subtract

Using complements, in neither case did


we have to do a subtraction.
A quick way to complement a number (i.e.
negate it):
Subtract each digit from 9
0000001 becomes 999998
and add 1
999998 becomes 999999
Complementing a number twice comes
back to the original:
999999 becomes 000000 then 000001
Any problems?
How do we know whether 999999 really
means 999999 or -1?
If you have 6 digits, you have 106 values.
If you want +ve and -ve values, you only
have half as many (106 / 2) of each.
So look at first digit:
000001 999999
0 means a forward number: 9 means a complement (a backward
this really is +1 number), so this is -1
In binary, it’s the 2’s complement system.
Same ideas apply, now in base 2.
E.g. to complement 0011 (= 310)
Subtract each digit from 1 (i.e. invert it)
0011 becomes 1100
and add 1
1100 becomes 1101 (= -310)
Complementing back:
1101 becomes 0010 then 0011
How do we know whether 1101 really
means -3 or +13?
If you have 4 digits, you have 24 (= 1610)
values, so if you want +ve and -ve
values, you only have 8 of each.
Again, look at first digit:
0011 1101
0 means a forward number: 1 means a complement (a backward
this is +3 number), so this is -3
Examples

0111 (710)
- 0011 (310)

Subtracting, so take
complement of
second value and
0111 (710)
then add it
+ 1101 (-310)
Ignore final carry
out when using
0100 (410)
complements
0100 (410)
- 0111 (710)

Subtracting, so
take
0100 (410)
complement of
second value
and then add it
+ 1001 (-710)
1101
Result is -ve so complement it
to obtain its value
0011 (310)
1101 (-310)
0100 (410)
- 1110 (-210)
Doesn’t matter
that second
value is -ve
already: use
0100 (410)
same procedure
+ 0010 (210)
0110 (610)
Questions

FIRST: what answer are you expecting?

01001010
- 00011101

00010011
- 10111001
Summary

Computers represent negative numbers in


2’s complement form.
To subtract a value they make it -ve by
complementing it, and then add it.
To complement a number, invert the bits
and add 1.
One of the commonest -ve numbers is
11111111

You might also like