-1

Can someone explain this question?

What is decimal value of the sum of the following 5-bit two's complement numbers? 10010+10101

Nik Bougalis
  • 10,495
  • 1
  • 21
  • 37

2 Answers2

3

Two's complement numbers are added together by doing binary arithmetic.

10010 + 10101 =


00111

Like normal numbers you carry the digit to the next place if you hit two ones at the same time while adding.

To interpret two's complement numbers, you have to understand that the first bit represents a value of 2^0, the second 2^1, the third 2^2, the fourth 2^3. This pattern extends for 32 and 64 bit numbers naturally. The final bit in 5bit two's complement represents -2^4.

Multiplying these values with the bits we came up with we have:

-0*2^4 + 0*2^3 + 1*2^2 + 1 *2^1 + 1*2^0

This value is 4 + 2 + 1 = 7. If we looked at the decimal value of 10010 we'd see its equal to -2^4 + 2^1 = -16 + 2 = -14. 10101 comes out to -11.

So the computer is saying that the sum of (-11) + (-14) is 7. This is because of overflow where we ignored the fact that the final bit should have had a 1 carry over into the next column. Giving a finite representation this is the best we can do.

The overflow is characterized by a bunch of neat properties since the representation we have is an Abelian group, a mathematical construct. It's outside the scope of the question but you should certainly understand them. Just google overflow.

Also, most answers are going to be curt since it's a basic topic that google could solve and StackOverflow gets enough questions as is. Make sure to check google and search StackOverflow before asking questions!

Anthony
  • 33
  • 4
-1
10010=2^4+2^1=16+2=18
10101=2^4+2^2+2^0=21
22+18=39

^=power
T.A.P
  • 69
  • 8