MHB Adding 8 bit 2's complement numbers.

  • Thread starter Thread starter shamieh
  • Start date Start date
  • Tags Tags
    Bit Numbers
AI Thread Summary
The discussion revolves around performing arithmetic operations with eight-bit 2's complement numbers and understanding overflow. The initial problem involves adding the numbers 01110101 and 11011110, where the second number is recognized as negative due to its leading bit. The confusion arises from the steps taken to handle the negative number, including inverting it and adding 1, which is unnecessary for direct addition in 2's complement. The correct approach is simply to add the two numbers directly. The outcome indicates a type of overflow, but it does not constitute arithmetic overflow since the result remains within the valid range of 2's complement representation. Arithmetic overflow specifically occurs when two positive numbers yield a negative result, which is not the case here.
shamieh
Messages
538
Reaction score
0
I don't understand something.

Perform the following operations involving eight-bit 2's complement numbers and indicate whether arithmetic overflow occurs.

If I have

$$
01110101
+11011110
$$

I know that the second term is negative because there is a 1 in front.

Now, because it is negative do I need to

1) Take the second term and invert it making it: 00100001.

2) then do I need to add the original form of it.. so: 11011110 + 00100001 = 11111111

3) Then add 1 to it? 11111111 + 1 = 11111110

4)Then go back to my original problem and put

01110101 + The new number? --> 111111110

and I know that if I have two positive numbers (both most left bit begins with zero, then I won't have overflow). But how will I know if I have overflow with these numbers?

Will my final answer be... 01010110 ? It doesn't make sense I follwoed this guys steps exactly and It just doesn't work
 
Technology news on Phys.org
shamieh said:
I don't understand something.

Perform the following operations involving eight-bit 2's complement numbers and indicate whether arithmetic overflow occurs.

If I have

$$
01110101
+11011110
$$

I know that the second term is negative because there is a 1 in front.

Now, because it is negative do I need to

1) Take the second term and invert it making it: 00100001.

2) then do I need to add the original form of it.. so: 11011110 + 00100001 = 11111111

3) Then add 1 to it? 11111111 + 1 = 11111110

4)Then go back to my original problem and put

01110101 + The new number? --> 111111110

and I know that if I have two positive numbers (both most left bit begins with zero, then I won't have overflow). But how will I know if I have overflow with these numbers?

Will my final answer be... 01010110 ? It doesn't make sense I follwoed this guys steps exactly and It just doesn't work

You're supposed to just add them.
It's a property of 2's complement that the result comes out the same, which makes 2's complement so useful.

As you can see, you get a kind of overflow.
This overflow is supposed to happen and it yields the correct answer.
This is not an "arithmetic overflow", since that indicates that the magnitude of the result is too large to fit, which is not the case.

You would get an arithmetic overflow if you add two positive numbers, and the result comes out as a negative number.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top