Amazon Interview Question

Write a function to determine whether a given number is a power of 2.

Interview Answer

Anonymous

Jun 25, 2011

public boolean powerOfTwo(int n){ return (n & (n-1) == 0) }

4