1
$\begingroup$

My task is to convert two numbers to binary, add them and determine if the result is correct as a NBC and 2's. Then I have to subtract B from A by converting by using 2's for calculating -B [that is A+(-B)].

The first number is 32723 -> 0111 1111 1101 0011

The second number is 5321 -> 0001 0100 1100 1001

The result of addition is 38044 -> 1001 0100 1001 1100

Now, I guess that this one above is correct as NBC, but what about 2's? Is this one considered as a negative value or is it positive?

For the second task -B is 1110 1011 0011 0111. Is it permitted to add two number whereas one is NBC and second is 2's?

$\endgroup$
2
  • 2
    $\begingroup$ What does "NBC" and "2's" mean here? $\endgroup$ Commented Jan 2, 2016 at 20:15
  • $\begingroup$ NBC = natural binary code, 2's = Two's complement $\endgroup$ Commented Jan 2, 2016 at 20:22

1 Answer 1

1
$\begingroup$

Is this one considered as a negative value or is it positive?

Since the most significant bit (MSB) is $1$, the number is considered as a negative value in 2's complement integer encoding. When you added $32723$ and $5321$, there was a $1$ carried into the MSB but not out of it. That sets up an overflow condition in 2's complement arithmetic: just about any CPU will have a condition flag for that. So in 2's complement the answer is not legitimate: it could not be done in the 16 bit integer format.

Is it permitted to add two number[s] whereas one is NBC and second is 2's?

Strictly no, but if the MSB of the Natural Binary Code (unsigned) number is zero the 2's complement representation is the same, so you are adding two 2's complement numbers and the operation is fine. So in this particular case you can add $A$ and $-B$ to correctly get $A-B$. In that addition you will get carry both into and out of the MSB, so there is no 2's complement overflow.

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.