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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -