ProgrammingModerate
The sequence n ^ (n >> 1) for n = 0, 1, 2, 3 gives what list?
- A. 0, 1, 2, 3
- B. 0, 2, 3, 1
- C. 1, 2, 3, 0
- D. 0, 1, 3, 2
Correct answer: D. 0, 1, 3, 2
These are the first four Gray codes, and consecutive values differ in one bit.
More C Programming questions
- For positive values below 2^31, which product is guaranteed to fit in a signed 64-bit integer?
- What is the multiplicative inverse of 2 modulo 7?
- In C, what is the result of 7 / -2 and 7 % -2?
- An unsigned short variable holds 65535 and is then incremented once with x++. What value does it hold?
- Which statement about left-shifting a negative signed integer in C is correct?
- How many subsets of {1, 2, 3, 4} (including the empty set) have XOR equal to 0?