Back In the print window choose "Save as PDF" as the destination
NOTE.CS

Bit Manipulation (common)

1 topic · 28 Nov 2026
1

Bit Manipulation (common)

Problem Solving
Problem: Power of 2 check and counting set bits.
Power of 2 check · C++
bool isPow2(int n){
    return n > 0 && (n & (n - 1)) == 0;
}
Count set bits · C++
int n = 13, count = 0;
while(n){
    count += n & 1;
    n >>= 1;
}
// or: __builtin_popcount(13)