ProgrammingVery hardProduct company OA
Assume 32-bit unsigned int. What is printed?
Assume 32-bit unsigned int. What is printed?
unsigned f(unsigned x) {
return (x & 0x55555555u) << 1 | (x >> 1) & 0x55555555u;
}
printf("%X", f(0xB4u));- A. 5A
- B. 50
- C. B4
- D. 78
Correct answer: D. 78
Precedence gives ((x & 0x55…) << 1) | ((x >> 1) & 0x55…): it swaps every pair of adjacent bits. 0xB4 = 10 11 01 00 becomes 01 11 10 00 = 0x78. '5A' is just x >> 1, and '50' is only the right-hand half of the OR.
More C Programming questions
- What is printed? c #define X 3 #define Y X 2 #if Y == 6 #define Z 1 #else #define Z 2 #endif printf("%d %d", Z, Y + 1 2);
- What is printed? c #define SHOW(x) printf(#x " = %d", x) int a = 3; SHOW(a 2 + 1);
- file1.c contains static int count = 5; at file scope. file2.c contains extern int count; and uses count in main. Nothing else defines…
- What is printed? c int a[] = {10, 20, 30, 40, 50}; int p = (int )(&a + 1); int q = &a[1] + 1; printf("%d %d %td", (p - 1), (q - 1), p - q);
- What is printed? c int a = 0, b = 1, c = 2; if (a++ || b-- && ++c) c += 10; printf("%d %d %d", a, b, c);
- What is the output? c int i = 0, s = 0; do { i++; if (i % 2) continue; s += i; } while (i < 7); printf("%d %d", i, s);