ProgrammingHardGATE CS · Campus placements
uint8_t x = 0xB7; uint8_t y = x | (x + 1); What is y?
- A. 0xBF
- B. 0xB8
- C. 0xB7
- 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
- The number of ways to tile a 2 x 6 board with 2 x 1 dominoes equals the number of binary tilings given by T(n) = T(n-1) + T(n-2) with T(1)…
- Intervals (1,4), (2,3) and (3,5) are stored as pairs in an array and qsort sorts them ascending by their second value. Which pair comes…
- Which of these statements are well defined by the C standard? I. uint8t x = 255; x = x + 1; leaves x equal to 0. II. int a = INTMAX; a + 1…
- What is the sum of the decimal digits of 2^20 = 1048576?
- uint16t a = 40000, b = 40000; uint32t s = a + b; What is s?
- uint32t x = 0x80000001u; x = (x << 1) | (x >> 31); What is x?