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

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -