fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool isPow2(int v) {
  5. return v != 0 && v == (1 << __builtin_ctz(v));
  6. }
  7.  
  8. int main() {
  9. cout << isPow2(0) << endl;
  10. cout << isPow2(1) << endl;
  11. cout << isPow2(2) << endl;
  12. cout << isPow2(3) << endl;
  13. cout << isPow2(4) << endl;
  14. cout << isPow2(5) << endl;
  15. cout << isPow2(6) << endl;
  16. cout << isPow2(7) << endl;
  17. cout << isPow2(8) << endl;
  18. return 0;
  19. }
Success #stdin #stdout 0s 4332KB
stdin
Standard input is empty
stdout
0
1
1
0
1
0
0
0
1