2

I need a bit advice of the following topics: adding two signed/magnitude and adding two complement binary numbers. I did my calculations on paper and uploaded the picture. Sorry if my picture is sideways (I don't know why the upload does that)

Adding two signed/magnitude

  1. +6 + (-6) Ignore the carry 1. The sum is 4 and incorrect. No overflow because we have added two numbers with different signed indicators, 0 and 1.

  2. +4 + (+5) The sum is -1 and incorrect. Overflow because we because we have added two numbers with the same signed indicators 0.

Adding two complement binary numbers

  1. +6 + (-6) Ignore the carry 1. The sum is 0 and correct. No overflow because we have added two numbers with different signed indicators, 0 and 1.

  2. +4 + (+5) The sum is -7 and incorrect. Overflow because we because we have added two numbers with the same signed indicators 0.

Did I understand correctly about binary addition overflow and sum correctness though my examples?

Pic

axesspwns
  • 113
  • 2
  • 14

1 Answers1

1

From this University course

4.11.4. Addition and Subtraction Addition and subtraction require attention to the sign bit. If the signs are the same, we simply add the magnitudes as unsigned numbers and watch for overflow. If the signs differ, we subtract the smaller magnitude from the larger, and keep the sign of the larger.

So for sign-magnitude you got the first one wrong.

The signs differ so you subtract the larger from the smaller. As they are the same, it doesn't matter what you pick. The result is 0 and it is correct. +0 or -0. It doesn't matter as they both represent the same thing.

You got the second one wrong too because for the sum +4+5, you should keep the sign + for the result and then add the magnitude. Which is

1         carry (ignore carry to the most sign bit)
0100  +4
0101  +5
--------
0001  +1

The result is +1 and there was an overflow that was detected by the carry out to the most significant bit, which is the sign bit.

Check this for more info http://pages.cs.wisc.edu/~smoler/x86text/lect.notes/arith.int.html


2's complement

Your answers are correct :tada:

GabrielOshiro
  • 7,986
  • 4
  • 45
  • 57