有人能帮我解释一下这个功能吗,谢谢!
int overflow(int x, int y)
{
int result, non_overflow, overflow, result_sign, mask;
result = x + y;
result_sign = result >> 31; //Need help starting from here... I know
//it is shifting 31 bits... but why??
non_overflow = ((x ^ y) | ~(y ^ result)) >> 31;
overflow = ~non_overflow;
mask = overflow << 31;
return (non_overflow & result) | (overflow & (result_sign ^ mask));
}