C++求2进制01不同的位数

开发技术 作者: 2024-06-19 07:50:02
#include &ltiostream&gtusing namespace std;int Grial(int x,int y){int count = 0;while(x!=0 || y!=0){if( ((x&0x1) ^ (y&0x1)) )count++;x&gt&gt=1;y&gt&gt=1;}return
#include <iostream> using namespace std; int Grial(int x,int y) { int count = 0; while(x!=0 || y!=0) { if( ((x&0x1) ^ (y&0x1)) ) count++; x>>=1; y>>=1; } return count; } int main() { cout<<Grial(2,15)<<endl; return 0; }

原创声明
本站部分文章基于互联网的整理,我们会把真正“有用/优质”的文章整理提供给各位开发者。本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
本文链接:http://www.jiecseo.com/news/show_29687.html