ProgrammingHard

A bit set of 64 flags is packed in one unsigned long long. Which expression tests flag 17?

  1. A. flags & 17
  2. B. flags == 1 << 17
  3. C. flags / 17 % 2
  4. D. (flags >> 17) & 1ULL

Correct answer: D. (flags >> 17) & 1ULL

Shifting right by 17 brings bit 17 to position 0, and masking with 1ULL reads it. The other forms test a number or a different bit.

More C Programming questions

Exams that ask this topic