# Signed binary subtraction using two's complement method

I'm sorry about this, but I'm at my wit's end. I'm trying do to an incredibly simple calculation. I want to calculate 4 - 7 using the two's complement method for signed binary numbers with a 4 bit register. I've been doing this calculation over and over again for an hour and I can't get the right answer no matter how hard I try and I can't figure out why.

4 = 0100 7 = 0111

2's complement of 7 = 1000 + 1 = 1001

0100 + 1001 = 1101 = -5

This is quite obviously wrong. The answer should be 1011 = -3

I found a handful of resources online that say that the two's complement of seven is 0111, which makes the math work but has nothing to do with the method as I learned it. I feel like I'm missing something painfully obvious but I don't have a clue what it is and it's about to drive me mad. Please help me, kind nerds of math.stackexchange!

• 1101 is -3. The rest of your computation is OK. – Fabio Somenzi Jan 25 '17 at 22:51
• How is that possible? 0011 is 3. Do I just not know how signed integers binary works? – Runic Jan 25 '17 at 22:55
• You computed -7 all right. Follow the same procedure, or the one I'm currently typing up in my answer. – Fabio Somenzi Jan 25 '17 at 22:56
• The rule for negating in 2's complement is "flip and add one". Flipping 3 = 0011 gives 1100 and then adding 1 gives 1101. Flipping 7 = 0111 gives 1000 and adding 1 gives 1001. – Rob Arthan Jan 25 '17 at 22:56

Here's a handy way to take the two's complement of a binary number. Start from the right and copy all digits up to and including the rightmost $1$. Then flip all other bits. It's not difficult to see that this is equivalent to flip and add $1$, but this method is faster and less error-prone.