ProgrammingHard
How many times does the loop x &= x - 1 run for x = 0b101100 before x becomes 0?
- A. 3
- B. 2
- C. 4
- D. 6
Correct answer: A. 3
Each pass clears the lowest set bit, so the loop runs once per set bit. 0b101100 has three set bits.
More C Programming questions
- For unsigned x = 40 (binary 101000), what is x & -x?
- Reversing the 8 bits of 0b00010110 gives which value in decimal?
- The Gray code of 5 (binary 101), computed as n ^ (n >> 1), is which value?
- What is the parity of the number of set bits in 0b1011, so that the result is 1 when odd?
- What is the value of 2 + 3 << 1 & 7 in C?
- What is the value of 5 ^ 3 & 1 in C?