c++ - shortest way to check if a positive integer is a power of two -


this question has answer here:

this question job interview...
use template write c++ function checks if positive integer power of two.

bool p(int n) {     return ********; } 

you have replace 8 '*' symbols other symbols in order make function work correctly.
best approach this:

bool p(int n) {     return !(n&=n-1); } 

unfortunately wrong, because there 9 symbols here...
ideas?

why assign n? remove = , have 1 character less. create temporary instead, logic won't change.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -