Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Doubt in two's complement

Status
Not open for further replies.
In order to answer this we need to know how many bits you're dealing with--3 or 4? In the 2's complement system, the MSB is always a sign bit. Your answer of '000' suggests it is '+00', whereas their answer suggests '-000'. Theoretically they are the same, but I think we need some more information from you before this can really be answered. Also, who is 'everyone'?
 
2's complement of 0 is 0...

In 2's complement you always ignore overflow

Start with 4 bit zero 0000
1's complement = 1111
Then add 1 and IGNORE the overflow
2's complement = 0000
 
Hi,

There is another interesting method for obtaining the two's complement. I found this most interesting because in part it is another example of how things in binary can simplify.

The old way is like this:
Start with the number say: 01001000
Negate each bit: 10110111.
Add 1 to the result: 10111000
Done.

The new way:
Start with the number: 01001000.
Look at each bit from right to left, any bit that is zero leave alone until you reach the first non zero, and leave that single non zero bit (1) alone also, so the last four bits are: 1000 and these get left alone, and the remaining four bits are 0100.
Now invert the remaining bits: 1011
Now put the number back together: 10111000
Done.
Note the result is the same as before.
The benefit seems to be that we never have to add, which can result in a ripple carry that could take a long time to calculate, and so we have to deal with each bit one time only no matter how many bits we have.

The 0000 example is even simpler, because it's all zeros, so all those zeros stay the same.

An example like this: 1000101
is also interesting, because we have no zeros on the far right, so everything to the left of the first 1 simply gets negated: 0111011
Lets check it:
1000101 negated: 0111010, add 1: 0111011
same result.

Also, an example like this: 1000 0000 0000 0000 (this is 16 bits)
becomes: 1000 0000 0000 0000
because we leave all the zeros and the first '1' encountered alone.
Lets check this one:
1000 0000 0000 0000 negated becomes 0111 1111 1111 1111,
and now to add 1 we have to ripple carry over all the digits from right to left when adding 1 to get: 1000 0000 0000 0000

The simplification in calculating the 2's complement starts to become clear.

Pretty interesting!
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top