1

So $10001011$ is an 8-bit two’s complement. Now what is the Decimal representation of the number $x$ represented by $10001011$? My steps:

  1. $10001011 -1$ and I get $01110110$

  2. Flip the digits and you get $10001001$

  3. Now I'm supposed to convert $1000$ and $1001$ into digits ($0$ to $9$) but am not sure how to do it efficiently, it'll take a lot of time to just start calculating. Any suggestions ?

JMCF125
  • 2,738
  • 1
  • 20
  • 34
kiasy
  • 127
  • Why do you flip the digits? I don't understand that method. Why don't you just do what @Logan Keefe suggested from start? – JMCF125 Dec 18 '13 at 20:17
  • 2
    @JMCF125: You flip the bits because that is the definition of two's complement for a negative number. The calculation Logan Keefe shows is how to get a decimal number from binary, but if you apply it here before the subtract 1 and bit flip you are treating the initial number as unsigned binary. You would then get $2^7+2^3+2^1+2^0=139$ – Ross Millikan Dec 18 '13 at 20:53
  • 2
    @kiasy Your subtraction of $1$ is not correct. $10001011-1=10001010$ – Ross Millikan Dec 18 '13 at 20:53
  • @RossMillikan, thanks. I didn't know the name of that operation. I should know it though, I came here from programming. :S – JMCF125 Dec 18 '13 at 22:36

3 Answers3

4

No, what you have is not right. The leading bit is $1$, so $10001011$ is the two’s complement of a negative number. To find the absolute value of that number, subtract $1$, getting $10001010$, and flip the bits, getting $01110101$. Now interpret this as an ordinary binary number, not as a pair of decimal digits. It’s $$2^6+2^5+2^4+2^2+2^0=64+32+16+4+1=117\;,$$ so your original number is $-117$.

Brian M. Scott
  • 616,228
1

In binary, the number places are powers of 2 with the rightmost place being 2$^0$, and the number in the place is what is multiplying the power, with each place being added together. The same goes for base 10 (decimal), but with powers of 10 instead. So let's look at your concrete example so this makes more sense.

For 1001, we have $1*2^3+0*2^2+0*2^1+1*2^0$. So, to get this in decimal, just preform the operations like you normally would. This, overall gives us $8+0+0+1=9$. So, 1001 in binary is 9 in decimal. Hopefully this helps.

  • Thanks @logankeefe. Can you just go over my calculating above and tell me if I did it right. – kiasy Dec 18 '13 at 20:05
  • I'm not familiar with the technique that you have used. The decimal representation of 10001011 is 139. You can use this to check your work. – Logan Keefe Dec 18 '13 at 20:37
  • 1
    The decimal representatio of the binary number $10001011$ is irrelevant: $10001011$ is not an ordinary binary representation. It’s the $8$-bit two’s complement representation of the integer $-117$. – Brian M. Scott Dec 18 '13 at 20:49
  • This doesn't really address the fact that the OP is talking about two's complement notation. (Not a comment to Brian - I am agreeing with his comment typed simultaneously!) – Old John Dec 18 '13 at 20:49
0

As a tip for the final binary to decimal conversion--what many programmers will do is convert first to hexadecimal, then convert to binary. The hexadecimal step makes the conversion process shorter, as one can easily memorize binary to hex conversions.

So, $0111\;0101_2$ is the same as $75_{16}$. (For the conversion to hex, note that $0111_2 = 7_{16}$, and $0101_2 = 5_{16}$.) To convert to decimal, now we just have to compute $$7\cdot 16 + 5\cdot 1 = 112 + 5 = 117_{10}$$

As pointed out in other answers, this is the negative of the original number, so we have the final result of $-117$.

apnorton
  • 17,706