Arithmetic Overflow: 8-Bit 2's Compl & Estimation of Overflows

  • Thread starter needhelp83
  • Start date
  • Tags
    Arithmetic
In summary, when performing operations on decimal numbers in 8-bit two's complement code, it is important to consider whether the result will produce an arithmetic overflow. This occurs when the result is larger than the range that can be represented in 8 bits (-128 to 127). By converting the decimal numbers to their two's complement form and performing the operations, we can determine if there is an overflow by looking at the leftmost bit. If it is 1, then an overflow has occurred. In the given examples, adding two negatives or subtracting a positive from a negative can result in an overflow. Additionally, the most negative number in two's complement is larger in magnitude than the largest positive number, as shown by the example of -
  • #1
needhelp83
199
0
Perform the following operations, representing the decimal numbers in 8-bit two’s complement code. Analyze whether the operations produce arithmetic overflow. Explain how you have estimated the overflows.

20 – 5; 127 –126; 127 – 128; -20 – 111; -20 – (+111);
- 43 - 120; -127 – 2; - 126 – 2.

I am having a very difficult time trying to understand this overflow concept. Any guidance would be greatly appreciated


*20-5
0001 0100 (20)
1111 0100 (-5) 2's

1 0000 1011

No overflow

*127-126
0111 1111 (127)
1000 0010 (-126) 2's

1 0000 0001 No overflow

*127 - 128
0111 1111 (127)
1000 0000 (-128) 2's

1111 1111 No overflow or carryout

*-20-111
1110 1100 (-20) 2's
1001 0001 (-111) 2's

1 0111 1101 Overflow (adding two negatives gives a positive)

*-20 - (+111)
1110 1100 (-20) 2's
1001 0001 (-111) 2's

1 0111 1101 Overflow (adding two negatives gives a positive)

*-43-120
1101 0101 (-43) 2's
1000 1000 (-120) 2's

1 0101 1101 Overflow (Adding 2 negatives gives a positive)

*-127-2
1000 0001 (-127) 2's
1111 1110 (-2) 2's

1 0111 1111 (Overflow 2 negatives gives a positive)

*-126-2
1000 0010 (-126) 2's
1111 1110 (-2) 2's

1 1000 0000 (No overflow)


Am I doing this correctly?
 
Physics news on Phys.org
  • #2
Any help?
 
  • #3
In twos complement you can represent a range -2^(n-1) to +2^(n-1) - 1
So in 8 bits you can fit numbers from -128 to 127
An interesting feature is that the most negative number is larger magnitude than the largest positive number.
 
  • #4
Have I shown this properly according to the instructions provided?
 

1. What is arithmetic overflow?

Arithmetic overflow occurs when the result of a mathematical operation exceeds the maximum value that can be stored in a given data type. This can lead to unexpected or incorrect results in calculations.

2. What is an 8-bit 2's complement?

An 8-bit 2's complement is a way of representing integers in binary form using 8 bits (or 8 digits). The first bit is used as a sign bit, with 0 representing a positive number and 1 representing a negative number. The remaining 7 bits are used to represent the magnitude of the number in binary form using the 2's complement method.

3. How does 2's complement affect arithmetic overflow?

In 2's complement, the most significant bit (MSB) is used as a sign bit. This means that when performing mathematical operations, the MSB must be taken into account to determine if an overflow has occurred. If the sign bit changes during the operation, it indicates that an overflow has occurred and the result may not be accurate.

4. How can we estimate the potential for overflow in calculations?

To estimate the potential for overflow, we can examine the data types and ranges of the numbers involved in the calculation. For example, if we are working with 8-bit numbers, we know that the maximum value that can be represented is 255. If our calculation results in a number larger than 255, we can estimate that an overflow may occur.

5. How can we prevent arithmetic overflow?

To prevent arithmetic overflow, we can use data types with larger ranges or precision, such as 16-bit or 32-bit integers. We can also use error handling techniques, such as checking for potential overflow before performing a calculation and using conditional statements to handle potential overflow scenarios.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
979
  • Engineering and Comp Sci Homework Help
Replies
2
Views
10K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
13K
  • Engineering and Comp Sci Homework Help
Replies
19
Views
34K
  • Advanced Physics Homework Help
Replies
11
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
Back
Top