ProgrammingHardCompetitive coding (CP)

What is printed? The reverse of the binary digits of 13 (1101) is taken as an integer.

What is printed? The reverse of the binary digits of 13 (1101) is taken as an integer.
#include <stdio.h>
int main(void) {
    unsigned x = 13, r = 0;
    while (x) { r = (r << 1) | (x & 1u); x >>= 1; }
    printf("%u", r);
}
  1. A. 13
  2. B. 11
  3. C. 7
  4. D. 14

Correct answer: B. 11

Reading 1101 from the low end gives 1011 = 11. Printing the original value would give 13.

More C Programming questions

Exams that ask this topic