int bitwiseComplement(int N){ int cnt=0, val=0; if(N==0) return 1; while(N){ val += !(N&1)*pow(2,cnt++); N>>=1; } return val; }