# Given a 8-bit processor, calculate 70 - 30 in binary and indicate if there is carry-out and overflow

I did the following exercise but even though I've revised my calculations several times, I don't seem to come up with the right answer:

Given a 8-bit processor and the variables $$a=30$$ and $$b=70$$, calculate $$b-a$$ in 2's complement. Indicate if there is a carry-out and overflow.

a. -40, there's overflow and carry-out

b. 40, there isn't overflow but there is carry-out

c. 40, there isn't overflow or carry-out

d. 296, there is overflow and carry-out

Apparently the right answer is b but I don't arrive to the same answer. This is what I do:

I first convert the previous numbers to the binary system.

$$70_{_{10}}=1000110_{2}$$ $$30_{_{10}}=11110_{2}$$

Since, we're dealing with 2's complements, I need to add a 0 at the beggining of each binary number. There:

$$70_{_{10}}=01000110_{2}$$ $$30_{_{10}}=011110_{2}$$

Since, the exercise wants me to subtract, I need to convert 30 to -30. To do that, I flip all the digits of 30 and add 1 up:

$$30_{10}=011110_{2}\Rightarrow 100001_{2}$$ $$100001_{2} + 1_{2} = 100010_{2}$$ Then, $$-30_{10} = 100010_{2}$$ Therefore, I just need to sum them: (Since there are more bits in 70 than in -30, I have to add 1s at the beggining of the binary number that represents -30)

Hence, I've found overflow and carry-out and it gives me $$100101000_{2}$$, which is -216.

Does anyone see the problem?

• Unless 70-30 gives you 40, there is a problem with your calculations. You need to fill out the binary representation of 30 to 8 bits before you take the 2-s complement. Mar 28 '18 at 21:38
• What are the definitions of "overflow" and "carry out" for your processor? These are not standard terms with a fixed mathematical meaning. Moreover, in subtraction, you don't "carry" but rather you "borrow" and you need to say how that is represented in the processor of interest. Mar 28 '18 at 21:51
• Bit 8 is the sign bit. Carry-out into bit 9 is discarded. Mar 28 '18 at 22:09
• @RobArthan As far as I know, when you're summing them, if you sum 1+1, it means that you carry out a 1 and I'd the result has more bits than the processor, overflow occurs Mar 28 '18 at 22:42
• "As far as I know" isn't good enough. You need to work from a precise definition. Mar 28 '18 at 22:57

$$\underbrace{/\!\!\!1}_{\text{carry out}}\underbrace{0010}_{2}\;\underbrace{1000_2}_{8} = 28_{16} = 40_{10}$$ there is a carry out, but there is no overflow bit.
The overflow checks the most significant bit of the 8 bit result. This is the sign bit. If we add two negative numbers (MSBs$=1$) then the result should be negative (MSB$=1$), whereas if we add two positive numbers (MSBs$=0$) then the result should be positive (MSBs$=0$), so the MSB of the result must be consistent with the MSBs of the summands if the operation was successful, otherwise the overflow bit is set.