题目描述
编写一个函数,确定需要改变几个位,才能将整数A转变成整数B。
给定两个整数int A,int B。请返回需要改变的数位个数。
测试样例:
10,5
返回:4
class Transform {
public:
int calcCost(int A, int B) {
// write code here
int num=A^B;
int count=0;
while(num)
{
if((num%2)==1)
count++;
num/=2;
}
return count;
}
};