20

Suppose I have the 2's complement, negative number 1111 1111 1011 0101 (0xFFBB5). How can I represent this as a decimal number in base 10?

Brian Minton
  • 105
  • 3
Bob John
  • 823

3 Answers3

26

Here is the process to convert a negative two's complement number back to decimal:

(1) flip all the bits,

(2) add 1, and

(3) interpret the result as a binary representation of the magnitude and add a negative sign

So, for your example, we have:

$$1111~1111~1011~0101 \xrightarrow{(1)} 0000~0000~0100~1010 \xrightarrow{(2)} 0000~0000~0100~1011 \xrightarrow{(3)} -75$$

It looks like you wrote the wrong binary and meant:

$$1111~1111~1011~1011~0101 \xrightarrow{(1)} 0000~0000~0100~0100~1010 \xrightarrow{(2)} 0000~0000~0100~0100~1011 \xrightarrow{(3)} -1099$$

Of course, in Hex, you can invert all the bits and add 1 and take a negative magnitude.

Regards

Amzoti
  • 56,629
12

If $x$ is an $n$ digit number written in two's complement, then ${\small\sim}x +1 = -x$, where ${\small\sim}x$ is the $n$-digit binary NOT of $x$. In your case, ~0xFFBB5 + 1 = 0x0044B = 1099, so your number is $-1099$.

ViHdzP
  • 4,854
  • 2
  • 20
  • 51
8

A very simple way of converting 2's complement negative number to decimal. Let a number 11010110, so the decimal representation of it is, –2^7 + 2^6 + 2^4 + 2^2 + 2^1 = – 128 + 64 + 16 + 4 + 2 = – 42 the idea is same as converting a normal binary number to decimal but with a negative sign with left most binary digit.

Nerd
  • 81
  • 1
  • 1