Goldman Sachs Interview Question

write a program to determine if a number can be expressed as 2^x. for example 4 is 2^2.

Interview Answer

Anonymous

Oct 10, 2012

bool isPowerOf2(int x) { return 0 == (x - 1) & x; }

1