I am doing a binary addition problem with two base-16 values and the one’s complement system. The answer I got on my problem is off by just 1, and I am wondering why that may be.
Whenever you are converting a negative base-2 number into a positive base-2 number when using the one’s complement system, are you supposed to add a 1 to the value? I know that whenever you are adding two base-2 numbers together, and you have a value you need to carry on the last step or the addition, you are supposed to add 1 to the answer. In my case, I did not have to carry anything on the last step of the addition, so I am unsure if I should be adding a 1 or not. Can someone help me out with this?
I have my work posted below for context. If you see another error with my work that is causing this discrepancy, please let me know!
Suppose you've got $n$ bits to represent your number. To take the ones-complement of a binary number $x$ is just to swap the $0$s for $1$s, and the $1$s for $0$. The exact same thing happens if you subtract $x$ from $111111...111_b = 2^n-1$.
So if you add $x$ and its ones-complement, you get $x + (2^n -1 - x) = 2^n -1$. This number is representable in your storage system, and is not $0$. If you use ones-complement to represent negative numbers, you cannot get the right result with ordinary addition procedures.
This is why the twos-complement was invented. The twos-complement adds $1$ to the ones-complement. So instead of $-x$ being represented by $2^n - 1 -x$, it is represented by $2^n - x$. When you add $x$ and its twos-complement, you get $2^n$, which is too big to fit in your storage, so all bits in storage are set to $0$, and you get an overflow bit that you can discard. The result is $0$.
So under ordinary addition rules, except discarding the overflow, The twos-complement of $x$ acts just like $-x$ under addition. For this reason, twos-complement is the most common choice for representing negatives.
If you want to use ones-complement to represent negative numbers, then you have to change how you do addition. The method is described here.