next power of 2 Algorithm

GCN graphics chips are fabricated with CMOS at 28 nm, and with FinFET at 14 nm (by Samsung electronics and GlobalFoundries) and 7 nm (by TSMC), available on choose models in the Radeon HD 7000, HD 8000, 200, 300, 400, 500 and Vega series of AMD Radeon graphics cards, including the separately released Radeon VII.GCN was developed by AMD for their GPUs as the successor to TeraScale microarchitecture / education set.
/*
 * Write a function that, for a given no n, finds a number p which is greater than or equal to n and is a power of 2.
 */
#include <iostream>

int next_power_of_2( int num ) {
  //already a power of 2
  if (num && !(num & (num-1))) {
    return num;
  }
  //count till msb set bit
  int count = 0;
  while ( num != 0 ) {
    num >>= 1;
    count++;
  }
  return (1 << count);
}

int main()
{
  std::cout << "Enter a number:";
  int num;
  std::cin >> num;
  std::cout << "Next power of 2 which is greater than or equal to " << num
            << " is: " << next_power_of_2(num) << std::endl;
  return 0;
}

LANGUAGE:

DARK MODE: