Skip to content

Instantly share code, notes, and snippets.

@ThunderXu
Created March 30, 2013 13:32
Show Gist options
  • Save ThunderXu/5276692 to your computer and use it in GitHub Desktop.
Save ThunderXu/5276692 to your computer and use it in GitHub Desktop.
Write a function to determine the number of bits required to convert integer A to integer B.
#include <iostream>
#include <bitset>
int GetNumber(int, int);
int main()
{
std::cout<<GetNumber(31,14)<<std::endl;
}
int GetNumber(int num1,int num2)
{
using namespace std;
int num3 = num1^num2;
bitset<32> btres(num3);
return btres.count();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment