ProgrammingHardGATE CS · Campus placements

uint8_t x = 0xB7; uint8_t y = x | (x + 1); What is y?

  1. A. 0xBF
  2. B. 0xB8
  3. C. 0xB7
  4. D. 0xFF

Correct answer: A. 0xBF

x + 1 flips the trailing ones of x and sets the lowest zero bit, which is bit 3. OR-ing x with 0xB8 sets that bit and gives 0xBF. This is the usual trick for finding the next zero bit.

More C Programming questions

Exams that ask this topic