# When is a bit CARRY and when is it OVERFLOW?

in dealing with UINT at a bitwise level

I can add, sub, mult and divide them and in each case determine if the result would no longer “fit” in the defined datatype… To me that is Over/Undeflow (depending on the operation)

But I have a calculator that seems to indicate BOTH Carry and Overflow in some cases

``````1111 + 0001 = [1]0000
``````

Yeah that one makes sense as it IS both
Its a carry OUT of the high bit
And also the result overflows

Basically the CARRY out causes OVERFLOW

but when would you have a CARRY and NOT Overflow
and when would you have OVERFLOW and NOT Carry

I’m thinking that “Sign” function comes into play here

Yeah I dont know the Casio well enough to say

I dont know if multiplication could generate an overflow without a carry
Carry is usually just the high bit rolling out
`0x8 + 0x8 -> 0x10`
Overflow is, usually, the result of any result thats too large
And it could be several bits that roll out
`0x8 * 0x8 -> 0x40`
so no carry but does overflow

I cant think of any case where you could have carry but NOT overflow

that sounds like Carry is for + and - where Overflow would be / and *

and to think in School I was an expert at this shit

well overflow can also happen in + and underflow in -
I dont think they are mutually exclusive
`0x8 * 0x2 -> 0x10 `
which I think would be both carry & overflow

but you’d need a real device to verify this on

Theoretically, at binary level (0/1), a Carry should be a one bit spill (the carry) you can recover and use, an Overflow should be more than 1 bit, and the result you get may be uncertain due to such “big” loss (as 2 bits ).

In a 4 bit register :

1111 + 1111 = (1 carry) 1101

``````// 15+15 or 15 * 2 results the same,
// MAYBE the firmware may consider 15 * 2 overflow + carry due to the spill not being
// caused by a sum/subtraction. You should observe the behavior being copied
``````

1111 * 11 = (10 overflow) 1101

``````// 15 * 3
``````