题目:
/*
* Return 1 when x can be represented as an n-bit, 2' s-complement
* number; 0 otherwise
*Assume1<=n<=w
*/
int fits_ bits(int x,int n);
补码加法的溢出有两种情况:正溢出,负溢出
/*Determine whether arguments can be added without overflow */
int tadd_ok(int x, int y) {
int sum = x + y;
int neg_over = x < 0 && y < 0 && sum >= 0;
int pos_over = x >= 0 && y >= 0 && sum < 0;
return !neg_over && !pos_over;
}