binary - C - Return 1 if any even-numbered bit in word x is set to 1 -
i stuck on function return 1 if bit set 1 using ! ~ & ^ | + << >>.
so far made mask 0x55 (0101) example, 1110 (true) masked return 0100 , 1010 (false) return 0000. how express answer true return 1 false return 0? thank edit: far code is:
int anyeven(int x){ int mask = 0x55; return (x&mask); }
int anyevenbit(int x) { return 0 != (x & 0x55555555); // assuming 32-bit int }
Comments
Post a Comment