top of page

Count number of bits to be flipped to convert a to b.

  • Writer: prashant raj
    prashant raj
  • Mar 18, 2022
  • 1 min read


#include <iostream>

using namespace std;

int main()
{
    int a = 3 , b = 4;
    int count = 0;
    int x = a ^ b;
    cout<<x<<endl;
    
    while(x) {
        if(x & 1)
        {
            count++;
        }
        x = x>>1;
    }
    cout<<count<<endl;
}

Commenti


Drop Me a Line, Let Me Know What You Think

Thanks for submitting!

© 2023 by Train of Thoughts. Proudly created with Wix.com

bottom of page