Computer Science 161.01
Professor Valente
Monday September 9th
READING: Section 3.2 pages 44-54.
The Ones Complement
Method for Representing Integers
If your high school algebra teacher was like mine, he or she said something about the additive inverse of
an integer being the
“opposite”. For example, the “opposite”
of +7 is -7.
Sure enough we were told that to solve x + 7 = 21, we could “add the opposite” to both sides
and get x = 14.
Let’s take this “opposite” approach to binary patterns.
If we represent +7 with eight bits we have 00000111.
What’s the opposite of this pattern, which has 5 0’s followed by 3 1’s?
Let’s consider the opposite pattern to be 11111000. Makes sense, right?
This is the ones complement approach.
The pattern 00000111 represents +7 so the negative of it is the opposite pattern 11111000.
Notice that, as with the sign-and-magnitude scheme, the left bit indicates the sign, 1 for negative.
OK, so what is 11001011 as a ones complement integer?
This is a negative number (starts with a 1) but which negative number?
First, let’s write the opposite pattern down first, and see what positive number that is.
The pattern 00110100 represents 52 (1->3->6->13->26->52)
so the pattern 11001011 must be
that for -52.
OK, so how does one write the 8-bit ones complement representation for -12?
Start first with +12 which is 00001100, then invert all the bits to get 11110011.
That’s it!
Try some ones complement exercises with this site that you are now accustomed to.
Be certain to select ones complement from the dropdown menu at the top of the page.
Is The Ones
Complement Method for Representing Integers a Good Method For Computers?
Not really! Why?
Well, because, as with Sign and Magnitude, two different patterns are interpreted as zero.
This time, they are 00000000 and 11111111. This is not the best use of patterns, is it?
In fact, the 256 patterns represent 255 different integers, from -127 (10000000) to +127 (01111111).
How about arithmetic?
Here, the situation is better than it was with Sign and Magnitude, but still flawed.
Recall, that with Sign and Magnitude, if I added the
patterns for 4 and -3, I got -7.
Let’s try a problem like 4 + -3 with Ones Complement:
The pattern for 4: 00000100
The pattern for -3: 11111100
-------------
Sum the patterns: 00000000 (column-by-column with carries)
Oh, great, that’s the pattern for 0! Which is 1 off from being correct!
In some sense, the Ones Complement method is 1 off from being the right method for computers.
We’ll fix that shortly by learning the Twos Complement method.