ProgrammingVery hardGATE CS · TCS NQT

What is printed?

What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint32_t v = 0xDEADBEEFu;
    v ^= v >> 16;
    v ^= v >> 8;
    v ^= v >> 4;
    v ^= v >> 2;
    v ^= v >> 1;
    printf("%u", v & 1u);
}
  1. A. 1
  2. B. 0
  3. C. 2
  4. D. 24

Correct answer: B. 0

XOR-folding the word down to its lowest bit yields the parity of its set bits. 0xDEADBEEF has 24 set bits, which is even, so the parity is 0.

More C Programming questions

Exams that ask this topic