Skip to content

VLSIFacts

Let's Program the Transistors

  • Home
  • DHD
    • Digital Electronics
    • Fault Tolerant System Design
    • TLM
    • Verification
    • Verilog
    • VHDL
    • Xilinx
  • Embedded System
    • 8085 uP
    • 8086 uP
    • 8051 uC
  • VLSI Technology
    • Analog Electronics
    • Memory Devices
    • VLSI Circuits
  • Interview
    • Interview Experience
    • Training Experience
    • Question Bank
  • Notifications
  • QUIZ
  • Community
  • Job Board
  • Contact Us
  • Toggle search form

Understanding Overflow through Examples

Posted on March 12, 2023March 12, 2023 By vlsifacts No Comments on Understanding Overflow through Examples

We have learned from the article “addition of 2’s complement signed binary numbers” that overflow occurs if the carries into and out of MSB are different. In this article, we will solve some examples that highlight how to detect overflow and how to avoid overflow.

Example:

Perform the following binary addition in 2’s complement arithmetic. Determine whether there is any overflow. If there is an overflow, then discuss how to avoid it.

(a) -7 + 10

(b) -10 + 7

(c) 10 + 7

(d) -10 + -7

Solution:

(a) -7 + 10 = ?

The two numbers given are -7 and 10. In this case, 10 requires five bits to be represented in 2’s complement form (one bit for sign and four bits for magnitude), whereas -7 requires only four bits (one bit for sign and three bits for magnitude). So, we need to add one more sign bit to the left of the MSB of -7 to make it 5 bits.

Important Rule for 2’s Complement Addition: We need to sign-extend one of the summands for proper summation. Both summands must have the same number of bits.

The five-bit representation of both numbers are 10 = 01010 and -7 = 11001.

Here, ‘n’ is the number of bits in the representation. So, n = 5.

To figure out whether, there is any overflow or not, we will perform XOR operation between Cn and Cn-1, as shown below. If the value of the XOR operation is ‘0’, then there is no overflow; if the value is ‘1,’ then there is overflow.

Example of no overflow

Since, in the above case, the carries into and out of the MSB are the same, the XOR operation between C5 (carry out of MSB) and C4 (carry into MSB) is ‘0’; therefore, there is no overflow. The other way to detect the overflow is to check whether the sum lies within the range of numbers (that can be represented by the 5 binary bits) or not, as shown in the above example.

Note: To get the final sum, we need to discard the carry out as shown in the above figure that we have learned in the article “addition of 2’s complement signed binary numbers“.

(b) -10 + 7 = ?

The five-bit representation of both the numbers are -10 = 10110 and 7 = 00111.

Another example of no overflow

In this example, there is no overflow as the result lies within the range.

(c) 10 + 7 = ?

The five-bit representation of both the numbers are 10 = 01010 and 7 = 00111.

Example of overflow

Since, in the above case, the carries into and out of the MSB are different, so the XOR operation between C5 (carry out of MSB) and C4 (carry into MSB) is ‘1’; therefore, there is an overflow. It can also be observed that the sum does not lie within the range of numbers that can be represented by the 5 binary bits.

Important Rule to Avoid Overflow: If the number of bits of the summands is n and m, then we need 1+ max(n,m) bits for the result to ensure no overflows.
 
Example of avoiding overflow

So in this example, to avoid overflow, we extended the summands by one more bit by adding another sign bit to the left of the MSB.

(d) -10 + -7 = ?

The five-bit representation of both the numbers are -10 = 10110 and -7 = 11001.

Another example of overflow

In this example, there is an overflow as the result lies outside the range. So, we will extend the bits of the summands to 6 bits.

Another example of avoiding overflow

The result is now free of overflow.

Reference: Oakland University, Digital Logic Design Course page.

Previous           Table of Content           Next

Spread the Word

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to email a link to a friend (Opens in new window) Email
  • Click to print (Opens in new window) Print

Like this:

Like Loading...

Related posts:

  1. What is Overflow in case of Binary Arithmetic
  2. Addition of 1’s Complement Signed Binary Numbers
  3. Rules of Binary Arithmetic
  4. Addition of 2’s Complement Signed Binary Numbers
Digital Electronics Tags:2's complement addition, Overflow, Sign extension, Signed Number Arithmetic

Post navigation

Previous Post: Interesting Facts Regarding Global Chip Shortage 2020-21
Next Post: Hexadecimal Arithmetic

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Top Posts & Pages

  • ASCII Code
  • Circuit Design of a 4-bit Binary Counter Using D Flip-flops
  • AND and OR gate using CMOS Technology
  • NAND and NOR gate using CMOS Technology
  • Difference between $display, $monitor, $write and $strobe in Verilog


 

Copyright © 2025 VLSIFacts.

Powered by PressBook WordPress theme

%d