Electronic – Converting hexadecimal digit to two’s complement

binaryhexmath

So I have the number 'E' which is 14 in decimal and 1110 in binary. To get the two's complement I first get the one's complement and add 1, so I get:

One's complement: 0001
Two's complement: 0010

So the answer in decimal form is 2, but the textbook says the answer is -2. What am I doing wrong here?

Best Answer

To get the 2's complement you must define the number of bits.

The most significant bit is the sign bit.

So if the number of bits is 8 then you should get:

  1. 14 is 00001110 (MSb=0 : positive)

  2. -14 is 11110010 (MSb=1 : negative)

if the number of bits is 4:

  1. you cannot code +14
  2. +2 is 0010
  3. -2 is 1110

2's complement of A is 2^n-A which we can get also if we apply: 1's complement + 1 (since the 1's complement is 2^n-1-A)

That is why 14 as raw binary is -2 as a 2's complement on 4 bits (it is 16-2 since 2^4=16) and there is a reason for that. In fact, the goal is to get a negative number coding where we can still have right results when applying basic operators like adding for instance on negative numbers, positive numbers and a mix of them.

Note: MSb is the most significant bit. Do not confuse with MSB (most significant byte).