ProgrammingHardGATE CS · Campus placements
uint8_t rev(uint8_t x) { uint8_t r = 0; for (int i = 0; i < 8; i++) { r = (uint8_t)((r << 1) | (x & 1)); x >>= 1; } return r; } What is rev(0x06)?
- A. 0x06
- B. 0x03
- C. 0x60
- D. 0xC0
Correct answer: C. 0x60
0x06 = 0000 0110, and reversing the eight bits gives 0110 0000, which is 0x60. Reversal is a classic building block for bit-manipulation problems.
More C Programming questions
- int a[] = {4, 9, 16}; int p = a; What is (p + 2)[-1]?
- To compute a b mod m with 0 <= a, b < m <= 1000000007 in a competitive program, which expression is correct?
- Which expression tests whether bit k of an unsigned x is set?
- int x = 0x1F; What does printf("%d", 07 + 0x1F) print?
- uint32t x = 0xFFFFFFFFu; How many times does while (x > 0) x >>= 1; execute its body, counting from the start?
- int cnt[3] = {0}; int p; for (p = cnt; p < cnt + 3; p++) p = p - cnt; What is the sum of cnt[0] + cnt[1] + cnt[2]?