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

999 Views Asked by At

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: enter image description here

(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?

Thank you in advance.

1

There are 1 best solutions below

4
On BEST ANSWER

$$\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.

Edit The carry-out refers to the bit that is "carried out" from the 8 bit adder, i.e., the 9th bit above. This is typically may used in conjunction with another adder (as the carry in) to make longer adders. It tells you nothing about whether or not the signed arithmetic being performed was successful.

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.