【C语言】求两个数中不同的位的个数

//求两个数中不同的位的个数#include <stdio.h>int count_different(int a, int b){int count = 0;int c = a^b;//a,b中不同的位即为1while (c){count++;c = c&(c – 1); //把c中最后一个1去掉}return count;}int main(){printf("%d\n", count_different(3,8)); //3printf("%d\n", count_different(0, 6)); //2printf("%d\n", count_different(-1,1)); //31return 0;}

版权声明:本文为博主原创文章,未经博主允许不得转载。

,还要高声歌唱。那歌声,一定是响遏流云的,

【C语言】求两个数中不同的位的个数

相关文章:

你感兴趣的文章:

标签云: