Power of 2

Give a one-line C expression to test whether a number is a power of 2.

Anwer:


#define IS_POW_OF_2(n) !(n & (num-1))

No comments: