我有我的位操作课外练习的最后一个问题的麻烦。该函数应该返回1,如果任何奇数位被设置为1 这是我到目前为止有:位运算用C - AnyOddBit
int anyOddBit(int x) {
return (x & 0xaaaaaaaa) != 0;
}
完美的作品,但我不允许使用一个常量,大的(只允许0到255,0xFF)。我也不允许使用=
具体来说,这是我有限的使用:
Each "Expr" is an expression using ONLY the following:
1. Integer constants 0 through 255 (0xFF), inclusive. You are
not allowed to use big constants such as 0xffffffff.
2. Function arguments and local variables (no global variables).
3. Unary integer operations ! ~
4. Binary integer operations &^| + << >>
我无法弄清楚如何在这些限制之内做到这一点,我真的如果有人能指引我朝着正确的方向感谢。提前致谢!
那么如何让比较小的值(S)? – 2012-04-23 01:05:18