-1

i tried 9 D + (-10 D)

9= 0000 1001

10= 0000 1010

Reverse 10 = 1111 0101 and add 1 become 1111 0110

after that add up 9 D + (-10 D) == 0000 1001 + 1111 0110 but the answer is equal to 1111 1111 whch is 255 in decimal but the answer should be -1 right? anything goes wrong?

Thank you very much.

Bilis
  • 125

2 Answers2

3

In two's complement, we deal with signed numbers by checking the leftmost bit. If this leftmost bit is a $0$, then it's positive, so we proceed like we do with unsigned numbers. Otherwise, if the leftmost bit is a $1$, then it's negative, so we have to do the "reverse the bits then add one" trick that you did when you converted $-10_{10}$ to binary. In general: $$ -x = \overline x + 1 \iff x = -(\overline x + 1) $$ Hence, since $1111~1111$ starts with a $1$ and we are dealing with two's complement, we have: \begin{align*} (1111~1111)_2 &= -((\overline{1111~1111})_2 + 1) \\ &= -((0000~0000)_2 + 1) \\ &= -((0000~0001)_2) \\ &= -1_{10} \end{align*}

Adriano
  • 41,576
  • thank you very much~ so if the answer ask us to show the answer in signed decimal value what i have to do? is it enough for me to show the answer like this? 0000 1001 (9) +1111 0110 (-10) equal to 1111 1111 (-1) – Bilis Aug 14 '14 at 05:49
  • Yeah. Personally, I'd show more work (how did you go from 1111 1111 to -1?). In terms of how much work you're supposed to show on an assignment or exam, that sort of thing is up to your teacher. – Adriano Aug 14 '14 at 06:27
  • alright~ thanks ya~^^ – Bilis Aug 14 '14 at 06:38
2

In two's complement representation for binary numbers, the number 1111 1111 represents -1. You missinterpreted the result as a "normal" binary number.

In two's complement, binary numbers of $2^n$ bits represent values ranging from $-2^{n-1}$ to $2^{n-1}-1$.

cjferes
  • 2,216