Hey I have a quick question:
How do I find out if an int is a power of 2 (only 1 positive bit) using bit-wise operators, in O(1) without any IF statements or any other type of BOOLEAN expression?
The method needs to return an integer value.
The method can return a certain number that you can decide on that means its a power of 2 and another number that means its not a power of 2. [Saying negative number means X and positive means Y is also allowed]
Also you can not rely on the fact that an int has 32 bits.
This is a question I was asked in an interview.