1

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 1's complement and 2's complement. I know what is signed number,signed magnitude and how binary digit stored in memory in 8bits,16 bits etc. But the problem is I couldn't understand why 1's 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 1's complement and 2's complement. But nothing explained why 1's 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.

Thanks In Advance Robin

Robin
  • 446
  • 2
  • 4
  • 24
  • 2
    The Wikipedia articles for 1's and 2's complement and binary numbers answer all of your questions and more. – Jonathon Reinhart Jan 18 '16 at 10:44
  • 1
    Especially the [Two's complement page](https://en.wikipedia.org/wiki/Two's_complement) contains the verbatim answer to you question: `The two's-complement system has the advantage that the fundamental arithmetic operations of addition, subtraction, and multiplication are identical to those for unsigned binary numbers (as long as the inputs are represented in the same number of bits and any overflow beyond those bits is discarded from the result). This property makes the system both simpler to implement and capable of easily handling higher precision arithmetic.` – fvu Jan 18 '16 at 10:45
  • An *encoding* is necessary to get everybody to agree what a set of 0 and 1 bit values means. Most obvious if you want to represent text, most everybody agrees that 01000001 means 'A'. Same applies to numbers, you have to agree on how to encode negative values. They made a sad mistake back in the 1960s, a mistake that keeps haunting this web site for no apparent reason. It is not important, other than teaching students that encoding is important. – Hans Passant Jan 18 '16 at 10:56
  • Deja-vu do-my-homework request. – Martin James Jan 18 '16 at 10:57

3 Answers3

3

1's complement is simply a Bitwise NOT gate, i.e. 1011 becomes 0100.

2's complements is the most commonly used to representation of signed integers because it obeys the rules of addition and subtraction.If you add 1 to 1111, you get 0000. Hence 1111 should be -1.

msc
  • 33,420
  • 29
  • 119
  • 214
0

You can use any system but some have cons or pros.

1's complement is very simple to understand but doesn't provide uniform arithmetic (when you want to add two numbers you have to distinguish different cases depending on the signs of the operands) so implementing it in hardware is too costly. Another problem is the existence of two 0 (a negative one and a positive one).

2's complement is slightly much harder to understand but provide a very simple uniform arithmetic, you just have to add numbers the same way whatever is the sign of the numbers (for example). So implementing it leads to a cheaper/smaller hardware.

Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69
0

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).

Vatine
  • 20,782
  • 4
  • 54
  • 70
  • Thank you very much for your great answer. After solving many mathematics problem in binary my experience is: in normal binary addition works well when working with 2 positive numbers or without any sign bit. But while doing addition or subtraction with negative numbers which have negative sign bits make problem. But it's possible to solve any addition or subtraction method with 2's complement method. – Robin Jan 19 '16 at 10:26