```
class Solution {
public:
int findComplement(int num) {
int sol = 0;
int next_set_bit = 1;
int lastbit;
while (num) {
lastbit = num & 1;
if (lastbit == 0) {
sol |= next_set_bit;
}
next_set_bit = next_set_bit << 1;
num = num >> 1;
}
return sol;
}
};
```