Two's complement representation allows the use of binary arithmetic operations on signed integers, yielding the correct 2's complement results.
The two's complement of a binary number may be produced very simply, in hardware or by hand, without resorting to visualizations of clocks or circular number systems. Given a binary number M, start with the rightmost bit and copy all bits up to and including the first 1 encountered; then complement (flip from 0 to 1 or vice versa) all the remaining bits.
Positive Numbers
Positive 2's complement numbers are represented as the simple binary.
Negative Numbers
Negative 2's complement numbers are represented as the binary number that when added to a positive number of the same magnitude equals zero.
The alternative to two's complement representation is to use a signed binary representation in which the number is represented by a sign and magnitude, which has been used in early computers (and even in representing floating point numbers in present systems).
The sign-magnitude has the advantage of being simple to use, understand and perform operations. However, this simplicity is only for us as humans with much sophisticated brain (CPU) and who are used to the signed magnitude decimal system and its operations from elementary school. For the computer, imagine performing addition of 2 bytes from each other. Using the signed magnitude system, a carry might propagate a number of times from one binary point to its neighbors. While in subtraction a long borrow process might as well be repeated. Thus complex hardware is needed while at the same time hardware for addition is different from hardware for subtraction. In twos complement operations hardware for addition is the same as hardware for subtraction because subtracting two numbers can be performed by adding the first to the negative of the second represented in 2's complement and the result is directly in 2's complement representation. Even multiplication can be done through successive addition and division can be done through successive subtraction. Additionally, the signed-magnitude representation has another flaw is that the zero is represented by two different representations (+0, -0) which is not in 2's complement (0 has one representation only). Thanks. @AlDmour.
Hi Ismat, Hemprasad and Vesa! I have two explanations of the (two's) complement code.
The first is based on the periodicity of the positional code with a fixed length. The sine wave can be a good example where we can express the negative number -270 (the lag) with the positive number 90 (a lead) or v.v.; so 90 is the 360's complement of the number 270. And if you add some number (e.g., 300) to both the negative and complement codes, you will get (after ignoring the carry) the same result: 300 + (-270) = 300 + 90 - 360 = 30 (we have discussed this "trick" with Lutz von Wangenheim in the question about the RC phase shift).
Of course, the best example is the two possible ways of expressing the time. We can say the time is "10 minutes to 12" (i.e., using the negative number -10). But with the same success we can say the time is "11 and 50 minutes" (i.e., using the 60's complement of the number 10). Thus, for example, if we add 20 minutes to the negative representation (-10) and to the 60's complement of 10 (50), we will obtain the same result (the carry is automatically ignored).
The second way of explanation is to think of the complement code as a shifted up (positive biased) with the maximum range negative number. I will illustrate it with a simple decimal example: 8 - 6 = 2. Here we suppose that our summing device cannot operate with negative numbers (like a n-p-n bipolar transistor that cannot work with negative input voltages). I ask my students, "What do we do then?". Of course, we can "move up" the negative number to the positive area by adding the maximum value (10, in this 1-decimal-digit example). Then we add the second positive number and finally, we move down the result by subtracting the maximum value (of 10 here):
From this "biasing" viewpoint, the more correct figurative name is "biased" ("lifted", "moved up", "shifted", etc.) instead "complementary" code. Transistor amplifying stages use the same biasing idea...