Goldman Sachs
Employer Engaged

Interview Question

Senior Developer Interview Jersey City, NJ

write a program to determine if a number can be expressed

  as 2^x. for example 4 is 2^2.

Interview Answer

1 Answer


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

HC on Oct 10, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.