ProgrammingHard
The Gray code of 5 (binary 101), computed as n ^ (n >> 1), is which value?
- A. 6
- B. 3
- C. 5
- D. 7
Correct answer: D. 7
5 >> 1 is 2 and 5 ^ 2 = 7. Successive Gray codes differ in exactly one bit.
More C Programming questions
- What is the parity of the number of set bits in 0b1011, so that the result is 1 when odd?
- What is the value of 2 + 3 << 1 & 7 in C?
- What is the value of 5 ^ 3 & 1 in C?
- unsigned int u = 1; int s = -2; printf("%u", u + s); What is printed with 32-bit unsigned int?
- With int a = -1 and unsigned int b = 0, what does the expression a < b evaluate to?
- Using the extended Euclidean algorithm, what is the inverse of 10 modulo 17?