Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- // WAP to check wheather the given number is in powers of 2 or not.
- bool is_power_of_two(int number) {
- return ((number & number-1) == 0);
- }
- int main() {
- cout << "is_power_of_two 0 " << is_power_of_two(0) << endl;
- cout << "is_power_of_two 1 " << is_power_of_two(1) << endl;
- cout << "is_power_of_two 2 " << is_power_of_two(2) << endl;
- cout << "is_power_of_two 13 " << is_power_of_two(13) << endl;
- cout << "is_power_of_two 26 " << is_power_of_two(26) << endl;
- cout << "is_power_of_two 52 " << is_power_of_two(32) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement