Data structures and algorithms
How many iterations does the loop while (x) { x &= x - 1; n++; } make on x = 255?
AppliedNumeric answer
How many iterations does the loop while (x) { x &= x - 1; n++; } make on ?
Answer with a number. Fractions, powers and expressions like 23/6 or C(52,5) are read correctly in practice.
The worked solution is in Premium
The answer, the full working and the one idea to take away – for this and all 1,322 questions in the bank. Answer it in practice and your working is marked, with a known mistake named when you make one.
Report an issue with this question
Learn the method
Of the kind reported at
Optiver, Citadel Securities, Hudson River Trading, Jump Trading
More data structures and algorithms questions
- What is 1oplus2oplus3oplus⋯oplus10, where oplus is bitwise XOR?Applied · Premium
- Computing x¹³ by binary exponentiation (repeated squaring), how many…Applied · Premium
- Finding the unpaired ids, part 2 of 3Applied · Premium
- Finding the unpaired ids, part 3 of 3Advanced · Premium
- How many set bits does the integer 90 have?Foundation · Premium
- For a positive integer x, which test is true exactly when x is a power of two?Foundation · Premium