How to Show Overflow Adding Binary Numbers
The limitation of processor structure can present problems when adding large numbers together. If the sum of two numbers is larger than the size of the storage location or the register, then you will save and use a false answer in future program calculations. The addition of two 8-bit numbers can result in a 9-bit number. This will only store the lower 8 bits of the sum for 8-bit registers.
Instructions
-
-
1
Place the number decimal 254 in the register of the processor. This will fit in an eight bit register. The binary representation of decimal 254 is 11111110.
-
2
Add the number decimal 2 to this number. The binary representation of decimal 2 is 00000010. These numbers illustrate the point of overflow when addition carries out in the processor.
-
-
3
Examine the problem when you sequentially add the bits of these two numbers. The first bit sum is zero. On the addition of bit, two of these two numbers has a carry in the result. The carry propagates all the way through the rest of the bits until bit eight. When adding bit 8 of the two numbers and applying the carry, the result is 10. The zero is filled into the position of bit 8 and the carry can't be held because there are no more positions open. Therefore, an error has occurred by producing an answer of, in decimal terms, 254+2=0.
-
1
Tips & Warnings
Always know that the numbers that you are adding are not going to cause an overflow due to the size of the integer being larger than the register size.