进入bits.c ,根据bits.c中的具体要求补全以下13个函数:
•intbitXor(intx, int y);
•inttmin(void);
•intisTmax(intx);
•ntallOddBits(intx);
•intnegate(int x);
•intisAsciiDigit(intx);
•intconditional(int x, inty, int z);
•intisLessOrEqual(intx, int y);
•intlogicalNeg(intx);
•inthowManyBits(intx);
•unsignedfloat_twice(unsigneduf);
•unsignedfloat_i2f(int x);
•intfloat_f2i(unsigned uf);
代码如下
//1
/*
* bitXor - x^y using only ~ and &
* Example: bitXor(4, 5) = 1
* Legal ops: ~ &
* Max ops: 14
* Rating: 1
*/
int bitXor(int x, int y) {
return (~(~(~x&y)&(~(x&~y))));
}
/*
* tmin - return minimum two's complement integer
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 4
* Rating: 1
*/
int tmin(void) {
return 1<<31;
}
//2
/*
* isTmax - returns 1 if x is the maximum, two's complement number,
* and 0 otherwise
* Legal ops: ! ~ & ^ | +
* Max ops: 10
* Rating: 2
*/
int isTmax(int x) {
return !((x+x+2)|!(~x));
}
/*
* allOddBits - return 1 if all odd-numbered bits in word set to 1
* Examples allOddBits(0xFFFFFFFD) = 0, allOddBits(0xAAAAAAAA) = 1
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 12
* Rating: 2
*/
int allOddBits(int x) {
int y=x>>