/*
* allOddBits - return 1 if all odd-numbered bits in word set to 1
* where bits are numbered from 0 (least significant) to 31 (most significant)
* Examples allOddBits(0xFFFFFFFD) = 0, allOddBits(0xAAAAAAAA) = 1
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 12
* Rating: 2
*/intallOddBits(intx){inta=170;a=a|(a<<8);a=a|(a<<16);return!((a&x)^a);}
/*
* floatScale2 - Return bit-level equivalent of expression 2*f for
* floating point argument f.
* Both the argument and result are passed as unsigned int's, but
* they are to be interpreted as the bit-level representation of
* single-precision floating point values.
* When argument is NaN, return argument
* Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while
* Max ops: 30
* Rating: 4
*/unsignedfloatScale2(unsigneduf){unsignedsign=uf&(1<<31);unsignedexp=(uf>>23)&0xff;unsignedfrac=uf&0x7fffff;if(exp==0xff){returnuf;}if(exp==0){frac<<=1;}if(exp!=0){exp+=1;}uf=sign|(exp<<23)|frac;returnuf;}
/*
* floatFloat2Int - Return bit-level equivalent of expression (int) f
* for floating point argument f.
* Argument is passed as unsigned int, but
* it is to be interpreted as the bit-level representation of a
* single-precision floating point value.
* Anything out of range (including NaN and infinity) should return
* 0x80000000u.
* Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while
* Max ops: 30
* Rating: 4
*/intfloatFloat2Int(unsigneduf){unsignedsign=(uf>>31)&1;intexp=(uf>>23)&0xff;signedfrac=uf&0x7fffff|0x800000;inttemp=exp-127;if(temp>31){return0x80000000u;}if(temp<0){return0;}temp=(temp>23)?(frac<<(temp-23)):(frac>>(23-temp));// 这里的左移和右移动手画画就出来了。
returnsign?-temp:temp;}
/*
* floatPower2 - Return bit-level equivalent of the expression 2.0^x
* (2.0 raised to the power x) for any 32-bit integer x.
*
* The unsigned value that is returned should have the identical bit
* representation as the single-precision floating-point number 2.0^x.
* If the result is too small to be represented as a denorm, return
* 0. If too large, return +INF.
*
* Legal ops: Any integer/unsigned operations incl. ||, &&. Also if, while
* Max ops: 30
* Rating: 4
*/unsignedfloatPower2(intx){intexp=x+127;if(exp<=0){return0;}if(exp>=0xff){return0x7f800000;// 都写到这里了,不会不知道 0x7f800000 是什么吧
}returnexp<<23;}