ProgrammingHardTCS NQT · Infosys
What is 0 ^ 1 ^ 2 ^ ... ^ 31, the XOR of all integers from 0 to 31?
- A. 31
- B. 0
- C. 32
- D. 1
Correct answer: B. 0
Prefix XOR of 0..n has the value 0 when n mod 4 is 3, and 31 mod 4 is 3. Pairs of equal bit patterns cancel, so the result is 0.
More C Programming questions
- What is the total number of 1 bits in the binary forms of 1, 2, ..., 16 added together?
- uint16t s = 0; for (int i = 1; i <= 1000; i++) s += i; What is s at the end?
- #define CAT(a,b) a##b. After int CAT(num, 2) = 7; what does printf("%d", num2 2) print?
- int a = 1 ? 2 : 3 ? 4 : 5; What is a?
- char p = "xyz"; char a[] = "xyz"; a[0] = 'Q'; printf("%s", a); What is printed?
- char s[4] = "abc"; What is sizeof s?