CareerCup-5.5

来源:互联网 发布:亦强软件报价 编辑:程序博客网 时间:2024/05/01 17:02
Write a function to determine the number of bits required to convert integer A to 
integer B 
Input: 31, 14
Output: 2

#include <iostream>using namespace std;int convertCount(int a, int b){    int t = a ^ b;    int count = 0;    while(t != 0)    {        t = t & (t - 1);        count ++;    };    return count;};int main(){    cout<<convertCount(31, 14)<<endl;    system("pause"); };


原创粉丝点击