Bit manipulation in Java
Common operations
&,|,^,~,<<,>>- check even/odd
- count set bits
- single number
- power of two
Example: count set bits
int countSetBits(int n) {
int count = 0;
while (n > 0) {
n &= (n - 1);
count++;
}
return count;
}Can you explain it without the notes?
Bit manipulation in Java
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
Common operations
Turn this concept into a clear answer.
Practice this conceptAdapted from 15_DSA_JAVA.md · “12. Bit manipulation in Java”. Examples are study fragments; framework behavior can depend on your version.