ProgrammingVery hardProduct company OA · GATE CS

Assume 32-bit unsigned int. What is printed?

Assume 32-bit unsigned int. What is printed?
unsigned x = 0xB8;          /* 1011 1000 */
printf("%u %u %u", x & (x - 1), x | (x - 1), x & -x);
  1. A. 176 191 3
  2. B. 184 191 8
  3. C. 176 191 8
  4. D. 176 183 8

Correct answer: C. 176 191 8

x − 1 = 1011 0111. x & (x − 1) clears the lowest set bit: 1011 0000 = 176. x | (x − 1) turns the trailing zeros into ones: 1011 1111 = 191. For unsigned x, −x is 2^32 − x and x & −x isolates the lowest set bit, whose value is 8 (not its position 3).

More C Programming questions

Exams that ask this topic