I want to check if number has all even or odd bits set to one and only them. For eg.:
Number 42
is correct, because in a binary code 101010
it has all and only even bits sets to 1
.
Number 21
is also correct, 10101
.
Number 69
for eg. 1000101
is not correct, because there are only three odd bits sets to 1
.
I've tried using different operations with ^, &, >>, <<
and i still have no idea how can i do this using these operators. Yes, i need to do this using logical operators in C
.