# Difference between carry and overflow

Carry is generally used for unsigned arithmetic and overflow is used for signed arithmetic.

This unsigned 8-bit operation results in Carry, but no overflow (the sign of the result is correct):

0xC0 + 0xD8 = 0x98

If we're doing unsigned 8-bit arithmetic, that's fine and we're only interested in the carry bit in this case, which tells us that the "correct" answer is actually 0x198.

If we look at the same operation and the same operand values, but consider that the operands are signed, we have the equivalent:

-0x40 + -0x28 = -0x68

In this case, there is also no "overflow" and the result of the arithmetic is correct.

Consider this unsigned operation, however:

0x70 + 0x68 = 0xD8

No overflow here -- and no carry. The unsigned arithmetic is simple. But now look at the operands as signed values:

0x70 + -0x98 = 0x28

The answer is obviously wrong. We have subtracted a larger number from a smaller one and ended up with a positive value. The carry is not set here, so it doesn't offer a clue of the problem. The overflow flag reveals that the "correct" signed answer is -0x28.

• The reason the last example is incorrect is because you're interpreting it as a negative overflow. 0x68 is a positive number if it's a signed 8 bits. The carry bit is set because 0x68 + 0x70 is 216, which is certainly greater than the largest positive 8 bit signed number (127). The result will be interpreted as a negative number, namely -128 + 88 = -40. The result we want however is +128 + 88 = 216.+
• your last example is obviosly uncorrect James Newton of MassMind replies: yes... that was the point of the example...+

+

• I believe the last example is incorrect. Adding a positive and negative number *never* results in overflow. The overflow flag is not the same as the sign bit. Overflow occurs when two large negative numbers are added and result in a positive, or when two large positive numbers are added and result in a negative.+

 file: /Techref/method/math/c-vs-o.htm, 4KB, , updated: 2016/10/18 12:29, local time: 2019/10/19 17:28, TOP NEW HELP FIND:  3.231.228.109:LOG IN

 ©2019 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?Please DO link to this page! Digg it! / MAKE! /  Difference between carry and overflow

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
 Did you find what you needed? "No. I'm looking for: " "No. Take me to the search page." "No. Take me to the top so I can drill down by catagory" "No. I'm willing to pay for help, please refer me to a qualified consultant" "No. But I'm interested. me at when this page is expanded."

### Welcome to sxlist.com!

Site supported by
& kind contributors
just like you!

(here's why

Copies of the site on CD
are available at minimal cost.

.