ProgrammingHardGATE CS · Campus placements
For an unsigned integer x, which expression clears the lowest set bit of x?
- A. x | (x * 2)
- B. x ^ (x >> 3)
- C. x & (x - 1)
- D. x & (x - 4)
Correct answer: C. x & (x - 1)
x - 1 flips the lowest set bit to 0 and the zeros below it to 1, so ANDing with x clears exactly the lowest set bit. The other forms do not do this: x | (x * 2) sets bits and the subtract-4 form clears a different pattern.
More C Programming questions
- uint8t a = 0xF0, b = 0x3C; uint8t c = a & ~b; What is c?
- uint16t a = 3, b = 5; printf("%d", (a - b) > 0); prints what?
- uint32t p = 65536u 65536u; What is p?
- uint64t f = 1; for (uint64t i = 1; i <= 21; i++) f = i; What is f after the loop?
- How many subsets of {1, 2, 3, 4, 5} have a bitwise XOR of their elements equal to 0? Count the empty set.
- How many integers i with 1 <= i <= 100 have bit 3 (value 8) set in their binary form?