ProgrammingHard
A bit set of 64 flags is packed in one unsigned long long. Which expression tests flag 17?
- A. flags & 17
- B. flags == 1 << 17
- C. flags / 17 % 2
- 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
- What is the first printed value of this loop? for (int i = 3; i > 0; i--) printf("%d", i);
- int x = 0; while (x < 3) x = x + 1; printf("%d", x); What is printed?
- int count = 0; for (char c = 'a'; c <= 'z'; c++) if (c != 'e' && c != 'i' && c != 'o' && c != 'u') count++; printf("%d", count); What is…
- printf("%d", 3 > 2 ? 'Y' : 'N'); What is printed?
- char names[] = {"x", "yy", "zzz"}; printf("%zu", strlen(names[2])); What is printed?
- int a[4] = {4, 3, 2, 1}; int s = 0; for (int i = 0; i < 4; i++) s = s 10 + a[i]; printf("%d", s); What is printed?