Binary in 2s complement form subtraction/addition help

  • Thread starter Thread starter Slimsta
  • Start date Start date
  • Tags Tags
    Binary Form
Click For Summary

Discussion Overview

The discussion revolves around performing arithmetic operations on binary numbers represented in signed 2's complement form, specifically focusing on subtraction and addition. Participants explore the calculations, verify results, and address the occurrence of overflow in each operation.

Discussion Character

  • Homework-related
  • Mathematical reasoning
  • Technical explanation

Main Points Raised

  • One participant presents a series of arithmetic operations involving binary numbers in 2's complement, asking for verification of their answers and clarification on handling overflow.
  • Another participant explains the process of converting binary numbers to their decimal equivalents, emphasizing the importance of recognizing negative values in 2's complement representation.
  • There is a discussion on how to handle subtraction by converting it into addition using the 2's complement of the second operand.
  • Participants explore the implications of overflow, noting that certain results may not be representable within the fixed bit-width of the binary format.
  • One participant expresses confusion about when to apply 2's complement and how to interpret results, leading to further clarification from others.
  • There are differing views on whether certain operations result in overflow, particularly in the context of the limitations of 6-bit representation.

Areas of Agreement / Disagreement

Participants generally agree on the methods for performing the arithmetic operations, but there is disagreement regarding the occurrence of overflow in certain cases, particularly in the last operation. The discussion remains unresolved on the specifics of overflow conditions.

Contextual Notes

Participants reference the limitations of 6-bit signed 2's complement representation, noting that it can represent values from -32 to +31. There is also mention of the need for careful consideration of carry bits when determining overflow.

Who May Find This Useful

Students learning about binary arithmetic, particularly in the context of computer science and digital systems, may find this discussion helpful for understanding 2's complement operations and overflow conditions.

Slimsta
Messages
189
Reaction score
0

Homework Statement


The following binary in signed 2s complement form. Perform the indicated arithmetic operations and verify the answers. Indicate whether overflow occurs for each computation.
a) 110001 – 010010
b) 001011 + 100110
c) 101110 – 110111
d) 100111 + 111001

Homework Equations



The Attempt at a Solution


a) 49-18=31 and
110001 – 010010 = 011111 (which =31)

b) 11+38=49 and
001011 + 100110 = 110000 (which =-48)
--> overflow

c) 46-59=-13 and
101110 – 110111 = 110111
-->2s comp --> = 001001 (which =-13)

d) 39+57=96 and
100111 + 111001 = 100000 (which =32)
--> overflowi hope my answers are right.. can you find any mistakes?
im just a little bit confused as to when to do the 2s comp once i get the answer (like in part C), should i try do the 2s complement just to try get the correct answer and avoid an overflow?
 
Physics news on Phys.org
Slimsta said:

The Attempt at a Solution


a) 49-18=31 and
110001 – 010010 = 011111 (which =31)
Ok, I'll go through this one step-by-step. Hopefully you'll get how to do the other ones.

Firstly, being 6 digit binary numbers, I'll number the digits from 0 to 5, with 0 being the least significant bit. So bit 5 is a sign bit. A number with a 1 in bit 5 is negative, and is a 2's complement of the number which is negative. For example:

110001 is negative. Let's find what number it is. Take it's 1's complement:
001110 Now add 1 to it:
001111 Which is equal to 15. Thus that number is actually -15

We don't want to actually use a subtraction here. That's part of the point of 2's complement. So we take out the subtraction by making the second operand negative and turning the operation into addition:
010010 Take 1's complement:
101101 Add 1:
101110 And that's the number in 2's complement form. We now do the operation as an addition:

110001+101110 = 011111
HOWEVER, we also overflowed. You know how to add binary numbers on paper, right? Super easy. The answer would come out to 31, yes, but it's wrong. Checking it out, we can convert them to non 2's complemented numbers. We get:

-15 - 18 = -33

Note how, since bit 5 is the sign bit which would otherwise be worth 32 that we can't really represent -33 in that small a space. The bit worth 32 is otherwise occupied. In fact, if you add two positive numbers that end up putting a 1 into bit 5, you would end up thinking that it's a negative number, but it's not. It would be an overflow as well.

That should be plenty to get you going on the next few. Of course, let me know if you have questions or didn't quite get it.
 
ok that makes sense.
so for part B, it would be 11+(-26) = -15
and i'd just leave the addition as 001011 + 100110 = 110001
take the 2's comp of 110001 since i have to return it to the original 2s signed # it would be 001111 which is 15 but it's negative so -15
no overflow here.

then part C, -18 - (-9) = -9
101110 – 110111 ==> 2s comp ==> 101110 + 001001 = 110111 (or -9)
no overflow here.

and part D, -25 + (-7) = -32
100111 + 111001 = 100000 (which =-32)
again, no overflow here.

is that correct?
 
Last edited:
You got it! Even the tricky one in D (mostly - see below). The largest negative number is kind of a special case. You can see that you can represent numbers from -32 to +31 with those 6 bits.

You might want to go through the wiki on 2's complement and read the addition section if you're not clear when a problem has occurred that would give an invalid result:

http://en.wikipedia.org/wiki/Two's_complement

If you carry out of the most significant bit (MSB) but not into it (or vice-versa), then you have a problem. But not all overflows (where a 1 is supposed to be carried but you're out of bits) lead to invalid values. So you might not be 100% correct on the overflows. I'd say that D does overflow, but the result is valid.

That last one does overflow, but it's not an error and the value is correct since it carries into AND out of the MSB. Anyways, the section on addition probably describes it better than I do (including a "trick" to quickly figure out if the result is invalid by looking at the carry bits).

But looks like you've got it. Good stuff. :approve:
 
sweet! It made sense to me when you explained it and i was like "hmm well that's easy stuff lol" and it took me like 5 minutes to fix my mistakes haha
i don't think my teach wants us to go into that deep level of explanations. if i get the same number for the result in binary and in normal digits and don't write "overflow", then she is happy with that.

Thanks a lot for your time and help!
 

Similar threads

  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 1 ·
Replies
1
Views
19K
  • · Replies 2 ·
Replies
2
Views
2K