```
int findComplement(long num) {
long i;
for(i=1;i<=num;i*=2) num^=i;
return num;
}
```

I basically check every bit of number by XOR'ing it with appropriate power of 2 which leads to its invertion.

For example:

```
Entered: 4=>100;
100 ^ 001 = 101;
101 ^ 010 = 111;
111 ^ 100 = 011;
Out: 011=>3;
```