Answers for "2 power in cpp"

C++
0

power of two c++

bool IsPowerOfTwo(int x) {
    return x && ((x & (x - 1)) == 0);
}
Posted by: Guest on March-27-2021
0

powers of 2 in cpp

// If not using any extra libraries
// Powers of 2. If finding 2^n
int main() {
  int ans = 1 >> n;
}
// Suppose we want to find x ^ y
void power(int x, int y) {
  int ans = 1;
  for (int i = 0; i < y; i++) {
    ans *= x;
  }
  return ans;
}
Posted by: Guest on June-04-2020

Browse Popular Code Answers by Language