ProgrammingVery hardCompetitive coding (CP)

How many zero bits are there in the low eight bits of 0xF0? Count them with this program.

How many zero bits are there in the low eight bits of 0xF0? Count them with this program.
#include <stdio.h>
int main(void) {
    unsigned x = 0xF0;
    int c = 0;
    for (int i = 0; i < 8; i++)
        if (!((x >> i) & 1u)) c++;
    printf("%d", c);
}
  1. A. 3
  2. B. 5
  3. C. 4
  4. D. 8

Correct answer: C. 4

0xF0 has four set bits in its high nibble, so the low eight bits contain four zeros.

More C Programming questions

Exams that ask this topic