Integer overflow: Difference between revisions

Content deleted Content added
No edit summary
Line 30:
Most computers have two dedicated processor flags to check for overflow conditions.
 
The [[carry flag]] is set when the result of an addition or subtraction, considering the operands and result as unsigned numbers, does not fit in the given number of bits. This indicates an overflow with a [[carry (arithmetic)|''carry''/ (''borrow'')]] from the [[most significant bit]]. An immediately following ''add with carry'' or ''subtract with borrow'' operation would use the contents of this flag to modify a register or a memory ___location that contains the higher part of a multi-word value.
 
The [[overflow flag]] is set when the result of an operation on signed numbers does not have the sign that one would predict from the signs of the operands, e.g. a negative result when adding two positive numbers. This indicates that an overflow has occurred and the signed result represented in [[two's complement]] form would not fit in the given number of bits.