16
Power of 2
void operator_q12_power_of_2() {
int numbers[] = {16, 18, 32, 50, 64};
for(int i = 0; i < 5; i++) {
int num = numbers[i];
if(num > 0 && (num & (num - 1)) == 0) {
cout << num << " is power of 2" << endl;
} else {
cout << num << " is NOT power of 2" << endl;
}
}
}
void operator_q12_power_of_2() {
int numbers[] = {16, 18, 32, 50, 64};
for(int i = 0; i < 5; i++) {
int num = numbers[i];
if(num > 0 && (num & (num - 1)) == 0) {
cout << num << " is power of 2" << endl;
} else {
cout << num << " is NOT power of 2" << endl;
}
}
}