I am revising for an exam i have in a weeks time. I have an example question which i have answered but i am unsure if it is correct. Could someone please verify my answer for me and explain where iv gone wrong if it was incorrect.
Here is the question: Consider two binary variables in sign-magnitude notation: A = 011111 and B = 000001. Showing all steps involved, perform the following operations in binary format (i.e., do not convert from binary to another radix in order to obtain the result). Assume you only have six bits available for the answers.
A-B Using two's complement.
Here is my answer: Use two's complement on B B = 000001 flip and add 1
111110
+000001
--------
111111
Then A + two's complement B
011111
+111111
-------
011110
Final answer: 011110
Subtraction using 2's Complement :-
Binary subtraction can be performed by adding the 2's complement of the subtrahend to the minuend. (Minuend in
a-b
is a and the subtrahend is b in this case)
If a final carry is generated, discard the carry and the answer is given by the remaining bits which is positive(the minuend is greater than the subtrahend).
If the final carry is 0, the answer is negative(the minuend is smaller than the subtrahend) and is in 2's complement form.
Now, 2's complement of B = 111110 + 1 = 111111.
Next, A + 2's complement of B = 011111 + 111111 = 1011110.
As you can see, the sum comes out to be in 7 bits and we have 1 as a final carry, so as per Rule 1, we need to discard the carry.
So, final answer = 011110.
Your answer matches this answer, hence, your answer stands correct.