SHARE
TWEET

Untitled

a guest Aug 12th, 2017 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. // WAP to check wheather the given number is in powers of 2 or not.
  5. bool is_power_of_two(int number) {
  6.     return ((number & number-1) == 0);
  7. }
  8.  
  9. int main() {
  10.     cout << "is_power_of_two 0 " << is_power_of_two(0) << endl;
  11.     cout << "is_power_of_two 1 " << is_power_of_two(1) << endl;
  12.     cout << "is_power_of_two 2 " << is_power_of_two(2) << endl;
  13.     cout << "is_power_of_two 13 " << is_power_of_two(13) << endl;
  14.     cout << "is_power_of_two 26 " << is_power_of_two(26) << endl;
  15.     cout << "is_power_of_two 52 " << is_power_of_two(32) << endl;
  16.     return 0;
  17. }
RAW Paste Data
Top