Kindly help me with this Binary calculation

Add the following 2's complement numbers 11 +01010101 = ?

How i solve it :

0000 0011 + 01010101 = 01011000 but the book say its 84???

Please help!

  • 1
    \$\begingroup\$ Your approach is reasonable. The question is misleading. \$\endgroup\$ – Pete Becker May 10 '15 at 18:04
  • \$\begingroup\$ The question is not misleading it is meant to require some thought, as in a leading 1 is a negative number \$\endgroup\$ – user76201 May 10 '15 at 18:57
  • 2
    \$\begingroup\$ IMO (as a teacher who teaches this kind of stuff) the question is badly 'worded'. It assumes that the 11 is to be interpreted as a 2-bit value, which is (unless made clear by context) not something one would automatically assume. Hence the question tests the students ability to see through this 'trick', NOT the students ability to do binary math. Maybe trickery is the subject of the course (and in that case the question is OK), but I doubt that. \$\endgroup\$ – Wouter van Ooijen May 10 '15 at 19:12
  • \$\begingroup\$ @WoutervanOoijen Also - are you adding a 2-bit value to an 8-bit value in an 8-bit context, or a 2-bit value to an 8-bit value in a 2-bit context? If the latter the answer would actually be 1. \$\endgroup\$ – Majenko May 10 '15 at 23:48

The two values have differing bit widths which you aren't taking into account.

The value 11 isn't the same as the value 00000011 when 11 comes from a 2-bit system. Instead, to take into account the two's complement sign you have to sign extend the smaller value into the same space as the larger value. That means copying the most significant bit into all the "new" bits you add to make it 8-bit.

So, 11 becomes 11111111. In two's complement, that equates to -1.

01010101 is decimal 85. 85 + -1 is 84.

Alternatively, in binary, 01010101 + 11111111 = 101010100 but since it's 8 bits the top-most bit gets lost, and the result is 01010100 which is 84.

  • \$\begingroup\$ Add the following 2's complement numbers \$\endgroup\$ – user2393690 May 10 '15 at 17:36
  • 1
    \$\begingroup\$ The fact that the numbers have different widths makes things rather unclear. The question is badly worded. \$\endgroup\$ – Majenko May 10 '15 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.