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.
See also:
Comments:
Questions:
file: /Techref/method/math/c-vs-o.htm, 4KB, , updated: 2020/6/1 09:07, local time: 2024/8/21 23:57,
3.128.170.142:LOG IN
|
©2024 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? <A HREF="http://piclist.com/tecHREF/method/math/c-vs-o.htm"> Difference between carry and overflow</A> |
Did you find what you needed? |
![]() o List host: MIT, Site host massmind.org, Top posters @none found - Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
Welcome to piclist.com! |
.