# Procedure for finding if Overflow occurs on addition

I have two 4-bit 2's complement numbers a,b, and their sum in s (Also a 4-bit 2's complement number). Using only the basic logical operations, I need to write a procedure to find if an overflow occurs. If there is an overflow, the output needs to be 1000 otherwise it is 0000.

The inputs in this procedure are a, b, s, and output is 1000 or 0000 depending on the inputs. I am allowed to use AND, OR and NOT operators

I know that there is an overflow if a and b have the same most significant bit and c has a different most significant bit but can't seem to figure out what the expression should be except that whatever the result is, needs to be ANDed with 1000 for the final result. How do I solve this?

(((NOT a) AND (NOT b) AND s) OR (a AND b AND (NOT s))) AND 1000