Question 8
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
unsigned x = 0xABCD;
printf("%X %X %X\n", (x >> 12) & 0xF, (x >> 4) & 0xFF, x & 0xF);
return 0;
}
- A A BC D Correct
- B A AB D
- C D BC A
- D AB CD D
Correct Answer: Option A
Each hex digit is 4 bits. Shift right by 12 and keep 4 bits: A. Shift right by 4 and keep 8 bits: BC. Keep the lowest 4 bits: D.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!