Determine the number of 1-bit pairs without overlap with other pairs in C. But My code does not include the first number. Like 11011 has 2 pairs of 1-bit but my output gives me 1 pair because it did not include the first number.
int numPairs(int n){ int count=0; bool prevOne=0; while(n!=0){ bool currOne=(n&1)==1; if(currOne && !prevOne) count++; n=n>>1; prevOne=!currOne; } return count/2; }
11and skip 2 bits if found (one if not)?prevOne=currOne? Why are you dividing by 2?