cbinarycomputer-sciencenumber-systems

What is the importance of 1's complement and 2's complement in Binary


I'm trying to learn binary number system and almost very new. I just finished some chapter on binary number conversation,addition,subtraction etc with some basic thing's.

But now I see a chapter on 1s' complement and 2's complement. I know what is signed number,signed magnitude and how binary digit stored in memory in 8 bits, 16 bits etc. But the problem is I couldn't understand why 1s' complement and 2's complement. Also why should we use 2's complement and why it's better etc.

I'm following a book it's have the guideline to convert into 1s' complement and 2's complement. But nothing explained why 1s' complement and 2's complement.

So I need some help to understand it more deeply. Any book suggestions for binary number system etc is appreciated.


Solution

  • 1s complement is simply bitwise NOT (that is 001 becomes 110), this ends up giving you two zeroes (111 and 000), so you need to take care when you're performing additions of numbers with different signs (and whenever you cross 0). It is, however, very simple to implement negation in hardware (it's a single parallel operation).

    2s complement adjusts the range, so you have one more negative than you have positive numbers (for 8-bit numbers, your range is -128 to 127), but you don't have to account for anything and you only have one zero. Negating a number is slightly more expensive (one parallel bit-flip, followed by an addition), but this is probably compensated for by much easier addition circuitry.

    Sign-bit simply uses the highest bit to signal negative or positive. It has essentially all the drawbacks of 1s complement. It is very simple to negate a number (flip the bit)

    There's also offset numbers, where an "all bits 0" number actually means "the most negative number" and "only the highest bit 0" means "the number zero". This may be appealing if, for example, you're using the number to control the displacement of something physical (all zeroes is all the way to one end, all ones all the way to the other and "zero" is in the middle).