0

So I wanted to calculate

$$765_{18}- 210_{3}$$

First converting $765_{18}$ into decimal: $765_{18} = 2381_{10}$.

Then converting $2381_{10}$ into binary: $2381_{10} = 100101001101_2$

Now converting $210_3$ into decimal: $210_3 = 21_{10}$

Two-complement of $21_{10} = 101011_{2}$

So I now want to add $2381_{10} +(- 21_{10})$ in binary (I just add the binary of $2381_{10}$ with the two-complement of $21_{10}$):

$$ 100101001101_2 + 101011_2 = 100101111000_2$$

I should get $2360_{10}$, but instead, I get $2424_{10}$.

  • Check your conversion from $210_3$ to binary. You appear to have one extra 1. – Matti P. Nov 08 '18 at 07:52
  • $210_3 = 21_{10} = 10101_2$? –  Nov 08 '18 at 07:55
  • Note that $2424_{10} - 2360_{10} = 64_{10} = 100000_{2}$, that should be a hint to the mistake – Christoph Nov 08 '18 at 07:55
  • @Christoph I guess that means I missed a 1 somewhere? –  Nov 08 '18 at 08:00
  • 1
    The error is in forming that two-complement. $2381_{10}$ is a 12-bit word when in binary. For the subtraction using two-complements to work, both numbers must have the same size. So when two-complementing $21_{10}=10101_2$ you must first extend it to a 12-bit entity $000000010101_2.$ – Jyrki Lahtonen Nov 08 '18 at 08:09
  • @JyrkiLahtonen Ahh, so that was it!! Thanks :) –  Nov 08 '18 at 08:11
  • TeachMeJava2017, if you figured this out, you are welcome to post the corrected calculation as an answer. That way 1) those of us who are unsure of how subtraction is done using two's complement will have an example, 2) you may get extra feedback on any lingering unclear points, 3) after waiting for a while for such feedback you can then mark the question settled (cleaning up our queue of unanswered questions by a tiny amount :-) – Jyrki Lahtonen Nov 08 '18 at 08:34
  • @JyrkiLahtonen I edited it and will close it later when its possible. Thanks again :) –  Nov 08 '18 at 08:45
  • 1
    @TeachMeJava2017 The answer should not be part of the question. So instead of editing the question to include the answer you should really post an answer. – Christoph Nov 08 '18 at 08:49
  • @Christoph Ok, did. (Didn't know this was actually allowed) –  Nov 08 '18 at 09:07

1 Answers1

1

After a hint in the comment I realized that I had to use $12$ bits for $21_{10}$, i.e. $-21_{10} = 111111101011_2$

Now one only has to add both of these:

$$100101001101_2 + 111111101011_2 = 100100111000_2 = 2360_{10}$$