i am having trouble to understand complement..

Thread Starter

transgalactic

Joined Apr 29, 2008
74
i am having trouble to understand the meaning
of complement 1 and complement 2 of a certain number

after looking a this table:http://s290.photobucket.com/albums/ll279/transgalactic/?action=view&current=IMG_8817.jpg

i came to the conclution that the complement 1 and complement 2 of a positive stays the same
but in the case of a negative number
there is a unique transformation for each type
of complement.

how does the complement to 1 and the complement to 2
changes the value of a negative number

and why it doesnt change possitive numbers
 

Papabravo

Joined Feb 24, 2006
21,159
You have it all wrong
The complement of a positive number is a negative number, and
The complement of a negative number is a positive umber

If A is a signed binary number and A' is the complement then in 2's complement notation
Rich (BB code):
A + A' = 0
and in 1's complement notation
Rich (BB code):
A + A' = 1.....11
Somewhat whimsically 1....11 in 1's complement notation is some times referred to as minus zero or -0.
 

Thread Starter

transgalactic

Joined Apr 29, 2008
74
i was told another thing which is completely makes sense like you words

besicly what he say is that possitiev numbers dont have any complement stuff
because a complement is a way to represent negative numbers
that expains why the positive numbers of the table were not touched

can you explain all this regarding this new comment
????


"
Ones complement and twos complement are methods of representing negative numbers. Therefore, they don't affect positive numbers.

To represent a negative number in ones complement, the positive value simply has all its bits inverted. Example: to represent -25 in ones complement, take the binary representation of +25 which is 00011001, then invert the bits: 11100110. Done.

To represent a negative number in twos complement, take the ones complement from the previous example, and add one to it: 11100110 + 00000001 = 11100111
"
 

Caveman

Joined Apr 15, 2008
471
First of all, let's ignore all of that and I'll explain it more simply.

Let's say you have 8-bits. There are 256 possible values, right? 00000000 to 11111111. That's all we get. But what do these different values mean? I mean what do they represent? There are a few possibilities:

1. They are just unsigned numbers from 0 to 255. This is pretty easy to understand. But we don't have any negative numbers now.

2. We can say that the first bit is a sign bit. If it is a 0, then the number is positive. If it is a 1, then it is negative. The rest of the number is just the magnitude. This is called signed magnitude. So we now have positive numbers for 00000000 to 01111111, or 0 to +127. The negative numbers are 11111111 to 10000000. So -127 to -0. Notice that we can no longer get as big positive numbers as before. We only go to 127 instead of 255. That is because we took the upper bit and made is a sign bit, so everything that was above 128 in unsigned numbers is now negative. There is a problem however. If you write this out in a sequence, the ordering of the numbers has changed.

Let me explain this better. Let's say you have -1, so 10000001. And you want to add 1 to it to get zero (1000000 or 00000000). To do this, you actually have to subtract 1. It would be nice if it just worked for a normal adder. So...

3. Let's use the sign bit again, but this time we want to invert (NOT operation) all of the bits in the magnitude for a negative number. This is ones complement. So positive numbers say the same, but negative numbers change a bit. The most negative number is 10000000, with a magnitude of 01111111, or 127. See how it is flipped in the representation? -1 is 11111110, so if we want to add one to it, we would get 11111111 which is a negative 0 (flip all of the 1's to zeros). However, we still have a problem. We have two numbers that both equal zero. So if we add one to 11111111, or -0, we get 00000000 (rolls over), which is positive 0. This doesn't really work right, so we need one more thing.

4. What if we do everything the same, but after flipping the bits of the negative number, we add one to it as well. Now, -1 has a 1 for the first bit because it is negative, then we flip 0000001 to 1111110. This is the same as ones complement. Then we add one, resulting in 11111111. This is the representation for -1. Now if we add 1 to it, we will get 00000000, which is zero.

How do we go back? All you have to do is do it again. So if it is negative, ie. the first bit is a 1, flip all of the other bits, then add one. So let's look at what happened to the -0 that we had in ones complement. What does it represent now? If was 10000000. It is negative, so we flip the other 7 bits and add one. 0000000->1111111 + 1 -> 10000000 = 128. So now the negative numbers go to -128.

Now, looking back at your table.
  1. On the first line, you have 22. You will notice that in all representations, positive numbers are all the same. The same goes for the last line.
  2. On the second line, you have -31. For signed magnitude, you just write out 31 magnitude in the lower 7 bits (0011111) and put a 1 for the signed bit, so 10011111. For one's complement, you just invert all of the bits for the magnitude, so (0011111->1100000) and keep the sign bit, so 11100000. For two's complement, add one to ones complement, so (11100000 + 1 -> 11100001)
  3. The third line works out the same as the second.
 

hgmjr

Joined Jan 28, 2005
9,027
Here is a link to the material in the Allaboutcircuit's ebook covering 1's and 2's complement. You will need to scroll down the page to locate the section covering the topic.

hgmjr
 

Thread Starter

transgalactic

Joined Apr 29, 2008
74
so i came to the simple conclution that the only represntation of a negative number
is by complemnt two system
so in order to find the number minus five we take
plus five 0101 and make the transformation>>1010>>1011
and in order to find the value of a negative number we make the same proccess again
1011>0100>0101 (5)

the is no meanig of representing a positive number in complement two
because it reserved for negative numbers
that wright??
 

Caveman

Joined Apr 15, 2008
471
so i came to the simple conclution that the only represntation of a negative number
is by complemnt two system
Nope, there are at least 3. Two's complement is really the only one that is typically used, though.

so in order to find the number minus five we take
plus five 0101 and make the transformation>>1010>>1011
and in order to find the value of a negative number we make the same proccess again
1011>0100>0101 (5)
That is the way it is done.

the is no meanig of representing a positive number in complement two
because it reserved for negative numbers
that wright??
Not exactly. Someone may say something like this: "The data is in 8-bit two's complement format." That doesn't mean that they are all negative. Two's complement is used to represent signed numbers. So you can represent positive and negative numbers (and zero). Of course, you only do the invert and add one process for the negative numbers, while the positive ones stay the same.
 
Top