Addition using 8-bit binary numbers with an 8-bit result

Thread Starter

jegues

Joined Sep 13, 2010
733
Given the following base 10 values:

a) 48 + 87

b) 48 + (-87)

c) -48 + (-87)

Preform the operations using 8-bit binary numbers and generate and 8-bit result. Clearly show the sum and carry generated. Also, indicate if an overflow condition has occured.

See figure attached for my work. Can someone verify if I'm doing this correctly?

Also if I want to indicate my negative result in two's complement do I need to invert all the bits again excluding the first 1 or do I keep as indicated in the figure? (i.e. Result in b) and c) )

Thanks again!
 

Attachments

Georacer

Joined Nov 25, 2009
5,182
Your operations are correct as far as I can see.

Your last result is negative as a signed negative number, because all the bits, from bit 8 and after (to the left) are 1s (with sign extension). You can't judge by the bit 7 bit because of the overflow of the adder.

In an 8-bit adder that result would be compromised and turned into 121 due to the loss of the first 1.
Therefore, it is essential to retain the carry in binary operations.
 

Thread Starter

jegues

Joined Sep 13, 2010
733
Your operations are correct as far as I can see.

Your last result is negative as a signed negative number, because all the bits, from bit 8 and after (to the left) are 1s (with sign extension). You can't judge by the bit 7 bit because of the overflow of the adder.

In an 8-bit adder that result would be compromised and turned into 121 due to the loss of the first 1.
Therefore, it is essential to retain the carry in binary operations.
I'm confused as to what you're trying to tell me about my last result. Is overflow occuring, is it incorrect?

Can you clarify?
 

Georacer

Joined Nov 25, 2009
5,182
Your initial numbers have 8-bits max, right? I start counting them from bit 0, the LSB, and reach up to bit 7.

If you do the addition and an overflow occurs (bit 8 is 1), that means that your 8-bit result is no longer valid. You need to look now at all of the nine bits to get the right result.

Of course, as you work with 2's complement and the 9-bit result starts with an 1, it is negative.
 

Thread Starter

jegues

Joined Sep 13, 2010
733
Your initial numbers have 8-bits max, right? I start counting them from bit 0, the LSB, and reach up to bit 7.

If you do the addition and an overflow occurs (bit 8 is 1), that means that your 8-bit result is no longer valid. You need to look now at all of the nine bits to get the right result.

Of course, as you work with 2's complement and the 9-bit result starts with an 1, it is negative.
Can't we also look at the carrys to determine overflow as well?

If we have a n-1 bit number then we simply xor the carries (Cn-1 xor Cn)

If this condition is satisfied, we have overflow.
 

Georacer

Joined Nov 25, 2009
5,182
Typically you have a set number of digits for your actions. Adders come in 4-bits or 8-bits in commercial IC's. You can build your own of course but I think that's impractical.

If you are set to recognize the negative numbers, you could look both at the carry out and the MSB. If at least one of them is 1, you can safely assume the number is negative.
 

Letech

Joined Dec 12, 2010
10
I think the operations that Jegues attached were all performed correctly and there is no mistakes on them.

Now my question or my wonder if you like is:
How do you convert 11011001 to decimal?
Referring to the picture that Jegues attached, when he tried to perform the subtraction of ( 48-87) in binary, you get totally different answer if you compare it to the value that you get when you perform the subtraction in decimal.

If you convert (11011001) by multiplying each bit by 2^n and then add them together you will end up getting 217 instead of -39. I know that 48 + (-87)=-39.

00110000-01010111 = 11011001
48-87 = -39

Shouldn't (00110000) - (01010111) must be equal to (48) - (87) ?!
If that was true,
then why when you convert (11011001) to decimal you don't get -39?

Is there something missing here or what?
 

Georacer

Joined Nov 25, 2009
5,182
Because the result is negative and encoded in 2's complement. Invert the digits and add 1 to find the absolut value of the result.

Wiki "two's complement" for more info.
 
Top