Flip consecutive set bits starting from LSB of a given number | C ++ program for the above approach ; Function to find the number after converting 1 s from end to 0 s ; Count of 1 s ; AND operation of N and 1 ; Left shift N by count ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findNumber ( int N ) { int count = 0 ; while ( ( N & 1 ) == 1 ) { N = N >> 1 ; count ++ ; } return N << count ; } int main ( ) { int N = 39 ; cout << findNumber ( N ) ; return 0 ; }