Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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

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

$ X - Y = ~ ??? $

$ Y - X = ~ ??? $

share|improve this question
1  
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 '13 at 23:57
    
Another hint: $X-Y = -(Y-X)$. –  gt6989b Feb 20 '13 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 '13 at 0:04
7  
Please stop defacing your questions. –  Andres Caicedo Feb 21 '13 at 5:38
1  
Amzoti and I have spent some effort to answer your question. Why did you delete it? –  Ross Millikan Feb 21 '13 at 6:14

2 Answers 2

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

share|improve this answer
    
Good work, Amzoti! +1 –  amWhy May 1 '13 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 '13 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 '13 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$$

share|improve this answer
    
@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 '13 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<Y$, but rather that the result is $X-Y+2^n$. –  MJD Feb 21 '13 at 0:25
    
@SilentMan: I would say you do two's complement to represent negative numbers. It is one representation, sign/magnitude is another. –  Ross Millikan Feb 21 '13 at 0:28
    
@SilentMan:$-128_{10}=10000000$ in two's complement as shown here If you have more bits, you put more $1$'s on the left. You can't represent $+128_{10}$ in a single byte of two's complement. –  Ross Millikan Feb 21 '13 at 0:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.