OK, I am not certain I can fully explain the
various methods used to represent signed numbers in general, but I can tell you that nearly every modern CPU architecture uses a method called
"two's complement" to represent signed integer values, while floating-point numbers generally use an approach called "signed magnitude" as defined by certain IEEE standards.
In 2's complement formats, for a given bit-width, positive numbers are represented by a range covering all but the most significant bit (MSB); thus, for one byte, a positive value would be one where the 8th bit is clear:
0XXXXXXX - where a valid positive number is between 0 and 127
Only negative numbers use the 8th bit, making it easy to determine if a number is negative or not.
Now, the naive approach to this might be to simply use the 8th bit as a sign bit, meaning that the absolute value of a given number has the same representation whether positive or negative. However, this approach requires additional hardware support, and also has a problem with having both +0 and -0, as well as other flaws which I don't think I understand well enough to explain.
The next solution is to take the
complement of the positive number and use that as the negative, the equivalent or applying [i](n XOR 11111111) to the value (for byte values). For example,
01101011
would become
10010100
This retains the ability to determine sign by checking the MSB, but doesn't require special hardware for handling sign (though most instruction sets do have a 'set to negative' instruction or standard sequence for producing a negative value). The problem with this is that it still has both a +0 and a -0.
The solution to this is to take the complement, then adding 1 to the result, meaning that the value above in 2's complement becomes:
10010101
The advantage here is that not only does zero have a single representation (since 11111111 + 1 wraps around to become 00000000), but due to some mathematical magic I don't properly understand, allows the exact same addition, subtraction, multiplication, and division hardware to work the same regardless of whether the value is signed or unsigned.