ProgrammingVery hardTCS NQT · Infosys
What is the bitwise XOR of all integers from 1 to 10, that is 1 ^ 2 ^ 3 ^ ... ^ 10?
- A. 11
- B. 10
- C. 9
- D. 1
Correct answer: A. 11
Prefix XOR of 1..n depends on n mod 4: it equals n when n mod 4 is 0, 1 when it is 1, n+1 when it is 2, and 0 when it is 3. Since 10 mod 4 = 2, the result is 11.
More C Programming questions
- What is the sum of popcount(i) for i = 1 to 8, where popcount counts the set bits?
- uint8t a = 0x3C, b = 0xA5; the statements a ^= b; b ^= a; a ^= b; run in that order. What are a and b afterwards?
- uint8t m = 0x0F; uint8t r = ~m; What is r?
- int a = -1; unsigned int b = 1u; What does if (a < b) evaluate to?
- int a = -7, b = 2; printf("%d %d", a / b, a % b); prints what?
- #define SQUARE(x) xx. What does printf("%d", SQUARE(2+3)) print?