IsPowerOfTwo
Returns true if the given number is a power of 2, false otherwise.
- Use the bitwise binary AND operator (
&) to determine ifnis a power of2. - Additionally, check that
nis different from0.
Returns true if the given number is a power of 2, false otherwise.
&) to determine if n is a power of 2.n is different from 0.