# Binary Subtraction of Two Unsigned Integers

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

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

$X - Y = ~ ???$

$Y - X = ~ ???$

-
What have you tried? Perhaps try to define 01-10 and 10-01 in binary first, and then try to tackle your problem. – gt6989b Feb 20 at 23:57
Another hint: $X-Y = -(Y-X)$. – gt6989b Feb 20 at 23:58
Yes I understand that this would come out to -10000000. However, "unsigned" integers can't be negative...so how do I do this then – Silent Man Feb 21 at 0:04
Please stop defacing your questions. – Andres Caicedo Feb 21 at 5:38
Amzoti and I have spent some effort to answer your question. Why did you delete it? – Ross Millikan Feb 21 at 6:14
show 2 more comments

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$$

-
 Good work, Amzoti! +1 – amWhy May 1 at 2:15 @amWhy: I have to admit that this has never been a good way to have defined it in general. I suppose this makes it easy for logic circuits, but hard for humans! :-) – Amzoti May 1 at 2:17 I agree wholeheartedly! But I enjoy doing "two's complement" arithmetic...I don't know why...I guess it's an exercise in logic, to some extent... – amWhy May 1 at 2:17

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$$

-
 @SilentMan: yes, the high order bit is not taken as a sign, it is taken as a bit of the number. So in $8$ bits you can represent the numbers $0$ through $2^8-1=255$, while with signed numbers you can represent $-128$ through $127$ in two's complement – Ross Millikan Feb 21 at 0:22 "Unsigned" computer arithmetic usually means that the operations are done $\bmod 2^n$, where $n$ is the word size. It does not mean that $X-Y$ is undefined when \$X