Binary Subtraction of Two Unsigned Integers

44k Views Asked by At

For unsigned integers $ X = 00110101 $ and $ Y = 10110101 $, determine the following values:

$ X + Y = (\text{My answer is}) ~ 11101010 $.

$ X - Y = ~ ??? $

$ Y - X = ~ ??? $

2

There are 2 best solutions below

3
On

Your answer is correct for $X+Y = 11101010$

Hint (Algorithm): $X-Y$

  • Determine $Y’s$ $2’s$ complement $X+$ (2’s complement of $Y$)

  • If $X \ge Y$, an end carry will result. Discard the end carry.

  • If $X \lt Y$, no end carry will result. To obtain the answer in a familiar form, take the 2’s complement of the sum and place a negative sign in front.

You may want to display in a different form, but you did not specify (hint: convert the first answer to 2's complement form).

$$X - Y = -10000000 ~~\text{and}~~ Y - X = 10000000$$

4
On

For $Y-X$ you do it just like base $10$. In this case there are no borrows. For unsigned, there is no answer to $X-Y$ because negative numbers cannot be represented.

$$\ \ \ 10110101\\ \underline{-00110101}\\\ \ \ 10000000$$