i need to flip all the bits except the first set bit from left side
like - > 001010111
res-> 001101000
i have did this with first converting to string and the fliping
how can we do the same with bitwise operators ?
string s = bitset<32>(n).to_string();
bool ok = false;
for(int i=0; i<s.size(); i++){
if(ok){
if(s[i]=='0')
s[i] = '1';
else s[i] = '0';
}
if(s[i]=='1'){
ok = true;
}
}
bitset<32> b(s);
return b.to_ulong();