1

So let's say I want to add -7 and -7 together using 2s complement binary notation. I tried this:

-7 -> -00000111 -> 11111001
  1 1 1 1 1 0 0 1
+ 1 1 1 1 1 0 0 1
__________________
1 0 0 0 0 0 0 1 0

But after removing the extra digit, I get 00000010 = 2 instead of 11110001 = 14. What did I do wrong?

2 Answers 2

5

Somewhere along the line, you lost (and kept losing) the carry flag:

          +- Here, 1 + 1 = 0 and sets carry to 1
          |   (everything up to here isokay).
          v
  1 1 1 1 1 0 0 1
+ 1 1 1 1 1 0 0 1
__________________
1 1 1 1 1 0 0 1 0
| | | ^ ^
| | | | |
| | | | +- Here, 1 + 1 + carry(1) is 1, not 0.
| | | +--- Ditto.
| | +----- And again.
| +------- Now it's just getting tedious.
+--------- Lastly, here is the final carry, just discard.

Negating 11110010 (invert bits and add 1) gives you 00001110, which is definitely 14 (8 + 4 + 2).

Sign up to request clarification or add additional context in comments.

1 Comment

Dang, that's a pretty basic mistake. Thanks a lot
1

Your math is wrong. Adding the 1 + 1 in position 5 gives you 10, so carry the 1. On the next column you need to add 1 + 1 + the carry, = 11 = 1 + a carry.

When you take this into account you end up with 1 1 1 1 0 0 1 0 = -14.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.