#
// get the n'th bit of a number
#
// the bit number starts from 0
#
#define BIT_N(number, bit_num) (((number)>>(bit_num))&0x1)
#
#define OVERFLOW(A,B,S) ((A)&(B)&(~(C))|(~(A))&(~(B))&(C))
#
#
#
//#define INT_OVERFLOW(a,b,s) OVERFLOW(a>>31,b>>31,c>>31)
#
#
int main()
#
{
#
char a = -4;
#
char b = -125;
#
char s = a + b;
#
int bp = sizeof(a)*8-1; // number of the last bit
#
int overflow = OVERFLOW(BIT_N(a,bp), BIT_N(b,bp), BIT_N(s,bp));
#
#
printf("for numbers a:%d and b:%d the sum is %d and overflow:%d\n", a, b, s, overflow);
#
}