int num = 28; //will round to 32 int exponent = (int)(log(num) / log(2)); exponent += 1; int pow2 = pow(2, exponent); //pow2 should contain 32