Carry and Overflow question. Really simple.

  • Thread starter DorumonSg
  • Start date
In summary, a carry occurs when adding two binary numbers results in an extra bit, while overflow occurs when adding two positive binary numbers results in a negative number. When both carry and overflow occur together, the overflow bit must be detected by checking for the overflow condition using the method described in the provided link.
  • #1
DorumonSg
64
0
Okay.

Let me get this right. A carry occurs when for example I add 2 8bits binary together and get 9 bits. The extra 1 bit is the carry right? (Means I get 1 extra bit from the original 2.)

So overflow means for example when I add 2 positive binary together, and I get a negative right? (Means the result is in the wrong sign.)

So what if a carry and overflow occurs together? Which is the overflow bit?

For example If I get the result 1011 when 1 is the carry bit and 011 is the result within range. Which is the overflow bit? 1 or 0? Is the overflow bit the carry bit? or must I take the MSB of the digit that is within ranger as the overflow bit?

Hope u understand my question?
 
Physics news on Phys.org
  • #2

1. What is carry and overflow?

Carry and overflow are two concepts in computer science that relate to the storage and manipulation of numbers. Carry occurs when the result of an operation is too large to be represented by the number of bits available, and overflow occurs when the result is too small to be represented.

2. How does carry and overflow affect calculations?

Carry and overflow can affect calculations by causing incorrect results or errors. In some cases, the computer may automatically adjust for carry and overflow, but in other cases, it may result in an unexpected outcome.

3. What is the difference between carry and overflow?

The main difference between carry and overflow is the direction of the error. Carry occurs when the result is too large, while overflow occurs when the result is too small. Additionally, carry is related to addition, while overflow is related to subtraction.

4. How can carry and overflow be prevented?

Carry and overflow can be prevented by using data types with a larger number of bits, such as using a 64-bit integer instead of a 32-bit integer. Additionally, certain programming languages have built-in functions to check for and handle carry and overflow.

5. Are carry and overflow always bad?

No, carry and overflow are not always bad. In some cases, they can be used to achieve certain results or to optimize calculations. However, in most cases, carry and overflow should be avoided to ensure accurate results.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
13K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
817
  • Engineering and Comp Sci Homework Help
Replies
4
Views
7K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
3K
  • Programming and Computer Science
Replies
1
Views
674
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
Back
Top