I am having a problem with the last issue of my homework. The function should return 1 if any odd bit is set to 1. Here is what I still have:
int anyOddBit(int x) {
return (x & 0xaaaaaaaa) != 0;
}
This works fine, but I'm not allowed to use a constant that is large (only 0 to 255, 0xFF is allowed). I am also not allowed to use! =
In particular, this is what I am limited to using:
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 & ^ | + << >>
I cannot figure out how to do this in these constraints, and I would really appreciate it if someone could point me in the right direction. Thanks in advance!
source
share