Need clarification regarding carry and overflow bit

  • Thread starter Thread starter leo255
  • Start date Start date
  • Tags Tags
    Bit
Click For Summary

Discussion Overview

The discussion focuses on the concepts of carry and overflow bits in binary arithmetic, particularly in the context of addition and subtraction of signed and unsigned integers. Participants explore definitions, implications, and examples related to these bits, aiming to clarify their meanings and applications.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant describes the carry bit as being set when there is an overflow into a bit that does not exist, while expressing uncertainty about the meaning of the overflow bit.
  • Another participant notes that the last bit is the sign bit, and an addition overflow can lead to a sign reversal.
  • A different participant explains that carry is primarily used for unsigned integers, while overflow pertains to signed integers, providing examples of how overflow can occur when adding positive and negative numbers.
  • Another participant clarifies that carry is relevant for unsigned addition, while overflow indicates a sign error in signed operations, and discusses scenarios involving multiplication and division.

Areas of Agreement / Disagreement

Participants express varying interpretations of carry and overflow, with some agreement on their definitions but differing views on their implications and applications in signed versus unsigned arithmetic. The discussion remains unresolved regarding the deeper understanding of the overflow bit.

Contextual Notes

Participants reference external sources for clarification, indicating that there may be varying definitions or interpretations of carry and overflow across different contexts or systems.

leo255
Messages
57
Reaction score
2
I'm trying to understand carry & overflow bits. Carry seems pretty easy - If I'm not mistaken, if you carry on your last bit into a bit that you don't have, the carry flag is set to 1.

For overflow, I referred to another previous thread on here, of which one of the posters recommended the thread-starter look at the following link:

http://teaching.idallen.com/dat2343/00s/overflow.txt

This was very helpful to me, by clarifying that the overflow bit is the exclusive or (XOR), and is set to 1 when either (but not both) of the last bit or carry bit has a 1 carried into it. When they both have a 1 carried into them, it is set to 0.

I feel like I understand how to determine the overflow bit, but I don't understand what it means. The carry bit is easy: you are adding two numbers, and just don't have enough room (enough bits), so you don't get an accurate representation of the number. Just trying to get the same understanding for the overflow bit.

Thanks in advance for the help.
 
Physics news on Phys.org
Carry is mainly used for unsigned integers, overflow is something similar for signed integers.

If you add 0100 + 0101 (let's use4 bits here), you expect a positive result because both numbers are positive. Simply putting them into your CPU will give 1001, however - that number is negative. The carry bit is not set (as both numbers are positive) but the first bit got set -> overflow.

In the same way, adding two negative numbers should give a negative result.
Adding 1100 and 1100 gives (1)0100 where (1) is carry - a positive result! Carry bit is set, but the first bit is not -> overflow

The two cases for subtraction can be studied in the same way.
 
Carry is set for unsigned addition. For unsigned subtraction, it's usually a "borrow" bit, but on some processors it's the "not borrow" bit.

Overflow is for signed addition or subtraction, and indicates that the sign of the result is wrong due to overflow (addition) or underflow (subtraction). For a signed or unsigned multiply with a double register product, overflow isn't possible. For a signed or unsigned divide with a double register dividend and single register quotient, the quotient can overflow (including division by 0).
 

Similar threads

Replies
3
Views
2K
Replies
3
Views
4K
  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 6 ·
Replies
6
Views
19K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
20
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 23 ·
Replies
23
Views
4K
  • · Replies 3 ·
Replies
3
Views
4K