Carry and Overflow are not the same thing!

I get questions about this a lot, so I thought I’d try and explain this. If we are to build an adder circuit from digital electronics, there is only one circuit which performs addition

signed and unsigned adder circuits are identical

The overflow and carry bits will be set or reset depending on the input values you apply. It’s more question of interpreting their meaning when you (mentally) convert back to decimal.

  • Contrary to what you might read, carry and overflow bits are not the same thing
  • If you consider your inputs to be signed, then you can simply ignore the carry bit (even if it is set) as it has no meaning for signed arithmetic
  • If you consider your inputs to be unsigned, then you can simply ignore the overflow bit (even if it is set) as it has no meaning for unsigned arithmetic

The carry and overflow bits are part of the device and always present, it’s just a question of how to interpret them. Remember the electronics knows nothing of signed or unsigned arithmetic – they are just binary values. It is all a matter of (human) interpretation.

For example, consider some 4-bit numbers:

  • Unsigned 4-bit values range from 0..15
  • Signed 4-bit values range from -8 to +7

Remember that signed numbers employ 2’s compliment arithmetic to ensure that binary addition and subtraction are consistent (e.g. x+(-x) = 0), as illustrated in one of the examples below.

Examples:

  • 0111b is interpreted as +7 in decimal, whether signed or unsigned.
  • 1000b is interpreted as +8 for unsigned , and -8 for signed.
  • 1001b is interpreted as +9 for unsigned , and -7 for signed.

The computer does not know any of the above – it just sees binary – how we choose to interpret the meaning is our decision.

Consider this addition:

  0111b
  1001b  +
1 0000b
carry = 1
overflow = 0

The carry bit is set, the overflow is not set.

  • For signed arithmetic, this was 7 + (-7) = 0 (we ignore the carry for signed arithmetic).
    • When you add a positive quantity to a negative quantity, it can never overflow
  • For unsigned arithmetic, this was 7 + 9 = 0, carry 1 (here the carry can be considered the msb – making this 16 in decimal)
    • Note how a carry is outside the 4-bit field

Now this:

  0111b
  0001b  +
0 1000b
carry = 0
overflow = 1

The carry bit is not set, but the overflow is (because two positive inputs produced a negative output).

  • For signed arithmetic, this was 7 + 1 = -8 (overflow is set, we ignore the carry)
    • The overflow it set because the result has a different sign to both inputs
    • An overflow can only occur if both inputs have the same sign.
  • For unsigned arithmetic, this was 7 + 1 = +8, carry 0 (ignore the overflow, but again we can use the carry as the msb of a 5-bit result if we choose)
  0011b
  0001b  +
0 0100b
carry = 0
overflow = 0
  • For signed arithmetic, this was 3 + 1 = +4 (overflow is 0, we ignore the carry)
    • The result has the same sign as both inputs
  • For unsigned arithmetic, this was 3 + 1 = 4, carry 0 (ignore the overflow)
  1101b
  1111b  +
1 1100b
carry = 1
overflow = 0
  • For signed arithmetic, this was -3 + (-1) = -4 (overflow is 0, we ignore the carry)
    • The result has the same sign as both inputs
  • For unsigned arithmetic, this was 13 + 15 = 12, (carry 1, we ignore the overflow)

Whether we consider the values signed or unsigned is up to us, the electronics is the same. All that changes is our interpretation of the result

I hope this clears things up.

By Nicholas Outram

Dr. Nicholas Outram is an Associate Professor in Computing and Electronics in the School of Computing and Mathematics, Plymouth University, UK. He specialises in iOS development, Biomedical Signal Processing, Embedded Software Development and VHDL. Dr. Outram has developed and heads-up an intensive fast-track iOS development course for students, academics and engineers both in Plymouth and overseas. He also develops iOS applications for research and teaching. Dr. Outram has a Ph.D. in Biomedical Signal Processing and Artificial Intelligence and a first class honours degree in Electrical & Electronic Engineering. Before returning to academia, he worked for 5 years in industry as a DSP engineer and research engineer.

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.