Finally getting two's complement
I think, you can&#x27;t address two&#x27;s complement without mentioning ones&#x27; complement.<p>So what is ones&#x27; complement? Simply all bits flipped. (XOR the word length – each bit becomes its complement.) There&#x27;s a simplicity and beauty to this and math just works with addition and subtraction. There&#x27;s also the notable feature of the most significant bit, which, if excluded from the usable range of numbers, becomes the sign-bit. If it is empty (clear), it must be a positive number, if it&#x27;s set, we have a negative number (since it must be a clear bit flipped).<p>So everything perfect, then? Not at all. What happens, if we flip all bits on zero (0000)? Well, it becomes all bits set (1111). How do we convert a number to it&#x27;s signed counterpart? We flip all bits and … Oh, this must be negative zero. Maybe we can deal with this? Sort of. But it&#x27;s somewhat nasty, because we need an extra steps to traverse zero. Say, we go from +1 to -1, there isn&#x27;t just a zero in between, making this a difference of 2 – as it should be –, but there&#x27;s +0 and -0. Three steps. That&#x27;s odd.<p>Can we do something about this? Namely, can we get rid of negative zero? Well, as we&#x27;ve seen, we have an extra step on the negative side of things… what about just adding 1 to compensate for this? So, for -1, we wouldn&#x27;t write 1110 (flipping all bits of 0001), but 1111? Just the same, for -2, we would add 1 to 1101, making this 1110, and so on. – Well, this works! we just eliminated negative zero! Welcome to two&#x27;s complement.<p>(So, is it now perfect? Well, sort of. We now have introduced a certain asymmetry into our number system: on the side of things, where the sign-bit is clear, zero is the first number and +1 the second one, while numbers with the sign-bit set start with -1. Thus, we have an excess number on the negative side of the number range described by our word length. We just can&#x27;t have it all. Well, we could switch to balanced ternary, but this is another story…)