r/AskComputerScience • u/Successful_Box_1007 • Feb 20 '25
What’s going on under the hood where 1’s complement requires an end around carry and an end around borrow but 2’s complement doesn’t?!
What’s going on under the hood where 1’s complement requires an “end around carry” and an “end around borrow” but 2’s complement doesn’t?!
Cannot for the life of me figure out WHY this is true. All I find online is the algorithm of how to perform 1s and 2s complement but nothing about WHY these “end around carry” or borrow must happen in 1’s.
Thanks so much!!!
6
Upvotes
3
u/Ragingman2 Feb 21 '25
In an 8-bit 2's complement system -1 is represented by "1111_1111". If you don't have special handling and add one to this value the natural result is "0000_0000", which means 0 in 2's complement.
This generally applies. The same addition rules that mean 5 + 6 = 11 ("0101 + 0110 = 1011") also mean that -5 + 6 = 1 ("1111_1011 + 0000_0110 = 0000_0001") when using 2s complement. For any other representation special rules are needed to handle negative numbers.
2
u/johndcochran Feb 22 '25
Ones complement and twos complement are merely specific cases of complements in general. A good explanation is this Wikipedia article
1
u/Successful_Box_1007 Feb 23 '25