In computer Architecture 2’s Compliment Number System is widely used. The discussion of overflow here mainly will we with respect to 2’s Complimentary System.
N-bit 2’s Compliment number System can represent Number from to
4 Bit can represent numbers from ( -8 to 7 )
5 Bit can represent numbers from ( -16 to 15 ) in 2’s Complimentary System.
Overflow Occurs with respect to addition when 2 N-bit 2’s Compliment Numbers are added and the answer is too large to fit into that N-bit Group.
A computer has N-Bit Fixed registers. Addition of two N-Bit Number will result in max N+1 Bit number. That Extra Bit is stored in carry Flag. But Carry does not always indicate overflow.
Adding 7 + 1 in 4-Bit must be equal to 8. But 8 cannot be represented with 4 bit 2’s complement number as it is out of range. Two Positive numbers were added and the answer we got is negative (-8). Here Carry is also 0. It is normally left to the programmer to detect overflow and deal with this situation.
Overflow Detection –
Overflow occurs when:
- Two negative numbers are added and an answer comes positive or
- Two positive numbers are added and an answer comes as negative.
So overflow can be detected by checking Most Significant Bit(MSB) of two operands and answer. But Instead of using 3-bit Comparator Overflow can also be detected using 2 Bit Comparator just by checking Carry-in(C-in) and Carry-Out(C-out) from MSB’s. Consider N-Bit Addition of 2’s Compliment number.
Overflow Occurs when C-in C-out. Above expression for overflow can be explained from below Analysis.
In first Figure the MSB of two numbers are 0 which means they are positive. Here if C-in is 1 we get answer’s MSB as 1 means answer is negative (Overflow) and C-out as 0. C-in C-out hence overflow.
In second Figure the MSB of two numbers are 1 which means they are negative. Here if C-in is 0 we get answer MSB as 0 means answer is positive(Overflow) and C-out as 1. C-in C-out hence overflow.
Readers can also try out other combination of c-in c-out and MSB’s to check overflow.
So Carry-in and Carry-out at MSB’s are enough to detect Overflow.
Above XOR Gate can be used to detect overflow.
- Turing Machine for addition
- Number System and Base Conversions
- Interface 8255 with 8085 microprocessor for addition
- Check if the binary representation of a number has equal number of 0s and 1s in blocks
- Allocating kernel memory (buddy system and slab system)
- Convert a binary number to hexadecimal number
- System Protection in Operating System
- Binary representation of next number
- 1's and 2's complement of a Binary Number
- Largest number with binary representation is m 1's and m-1 0's
- Convert a binary number to octal
- Binary representation of previous number
- Check if binary representation of a number is palindrome
- Prime Number of Set Bits in Binary Representation | Set 1
- 8085 program to convert a BCD number to binary
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.