13
3 Explanation: 13 → binary 1101 → three 1s)
void operator_q11_count_set_bits() {
int num = 29; // Binary: 11101
int count = 0;
int temp = num;
while(temp > 0) {
if(temp & 1) { // Check last bit
count++;
}
temp = temp >> 1; // Right shift
}
cout << "Number: " << num << endl;
cout << "Set bits (1s) in binary: " << count << endl;
}
void operator_q11_count_set_bits() {
int num = 29; // Binary: 11101
int count = 0;
int temp = num;
while(temp > 0) {
if(temp & 1) { // Check last bit
count++;
}
temp = temp >> 1; // Right shift
}
cout << "Number: " << num << endl;
cout << "Set bits (1s) in binary: " << count << endl;
}