I'm afraid the Solution 1 and Solution 2, correct in principle, did not uncovered the essence of things. Here is the trick: the binary representation of integer numbers is
specially designed the way ignoring the difference between unsigned numbers. This representation is dominated in almost all modern systems and is called "2's complement". Here is how it works:
http://en.wikipedia.org/wiki/2%27s_complement[
^].
Here is the idea: let's say, you have the binary representation of byte (integer number of any size, actually, this is only an example) of 11111111. It represents unsigned 255=0xFF or signed −1. Different mathematical values, right? Let's add some other byte to is, say, (same mathematical value for both signed and unsigned). Let's add them formally, using school "column" method and carrying over to left the bit in case of overflow:
11111111
+
00000011 = 3
=========
00000010 = 2
In both signed and unsigned representation, we have the same result (in case of unsigned, we also have "wrap around" effect: adding 1 "increment" maximum value of 255 to 0, and adding 2 makes the result equals to 2).
In some other cases, we get different mathematical values but the same binary result. For example:
11110110
+
00000010 = 2
=========
11111000
In signed values, it means −10 + 2 = −8, in unsigned: 0xF6 + 2 = 0xF8, or 246 + 2 = 248.
You can check up and see that the same takes place in all other integer arithmetic operations. As you can see, the CPU does not care about signed and unsigned representations; all calculations are the same, only the interpretation of the results are different. You can also check up that you can mix signed and unsigned values in the same expression, but need to take care about not crossing the barriers of the maximum and minimum values, which are of course different.
Also, you should understand that the absolute values of signed negative value is not the same as the signed value with flipped sign bit. If you have −1, flipping the sign bit won't give you 1, it will be 127. It has important implication: there is no binary two representations for zero, −0 and +0 has the same representation.
—SA