Wednesday, August 3, 2022

TIL: Why is Two's complement used?

 Two's complement is a widely known way of handling negative numbers in Binary. Today, I was looking for the answer to "Why do we use two's complement instead of how normal subtraction works with binary numbers?". And thanks to Stack Overflow, I found the answer.

All credits to the StackOverflow post that was trying to answer the same question. (Also adding the Wikipedia article in case StackOverflow is lost).

Since the referred sources are pretty good at explaining all the details, I will just put the summary here.

Basically Two's complement is preferred because it helps reduce the number of operations required to handle Negative numbers much more less. In fact, it's just addition. To keep the process simple as adding 2 numbers, we use the complement so that 1+1=0 happens and any carries at the end are discarded.

Someone has even put a more detailed explanation on why this works here.

TIL: Why is Two's complement used?

 Two's complement is a widely known way of handling negative numbers in Binary. Today, I was looking for the answer to "Why do we u...