代码实现如下:
#include<iostream>
using namespace std;
bool fun(int num);//通过位运算判断一个数是不是2的整数次方,这个数只有一个1
void test(int num);
int main(){
test(17);
test(16);
return 0;
}
void test(int num){
if(fun(num))
cout<<num<<"是2的整数次方"<<endl;
else
cout<<num<<"不是2的整数次方"<<endl;
}
bool fun(int num){
int sum = 0;
num = (num-1)#
if(num == 0)
return true;
else
return false;
}