给定两个整数A和B,需要改变几个二进制位才能将A转为B。

上代码

#include<iostream>
using namespace std;
int main(){
    int a,b,c,d,e;
    int count=0;
    cin>>a>>b;
    c=a&b;
    d=a|b;
    e=c^d;
    while(e!=0){
        e=((e-1)&e);
        count++;
    }
    cout<<count<<" ";
    return 0;
}
posted @ 2024-06-04 12:20  pengfu_xin  阅读(2)  评论(0编辑  收藏  举报