ProgrammingVery hardProduct company OA

What is printed?

What is printed?
unsigned char rotl(unsigned char v, int k) {
    return (unsigned char)(v << k | v >> (8 - k));
}
int main(void) {
    printf("%02X %02X", rotl(0x96, 3), rotl(rotl(0x96, 3), 5));
}
  1. A. 4B 96
  2. B. B4 69
  3. C. B4 96
  4. D. B0 96

Correct answer: C. B4 96

0x96 = 1001 0110. Rotating left by 3 moves the top three bits (100) to the bottom: 1011 0100 = 0xB4. Rotating by 5 more completes 8, a full circle, giving 0x96 back. 'B0' is a plain shift that loses the wrapped bits.

More C Programming questions

Exams that ask this topic