1, programming implementation: two int (32-bit) integer m and n binary expression, how many bits (bit) is different?
#include <stdio.h> #include <string.h>int bits_compare (int num1,int num2) {int A[32]={0};int b[32]={0};int I =0;int count=0;for (i=0;i<32;i++)//num1 binary conversion {A[I]=NUM1%2;NUM1=NUM1/2;} printf ("12 binary:"); for (i = 31;i >= 0;i--)//Adjust the format and output the result {printf ("%d", a[i]), if (i%4 = = 0) {printf ("");}} printf ("\ n"); for (i=0;i<32;i++)//num2 binary conversion {B[I]=NUM2%2;NUM2=NUM2/2;} printf ("22 binary:"), for (i = 31;i >= 0;i--) {printf ("%d", b[i]), if (i%4 = = 0) {printf ("");}} printf ("\ n"); for (i=0;i<32;i++)//Compare {if (A[i]!=b[i]) {count++;}} printf ("count=%d\n", count);} int main () {int m=0,n=0;int count=0;int arr1[32]={0},arr2[32]={0};p rintf ("Please enter two M, N:"); scanf ("%d%d", &m,&n); Bits_compare (m,n); return 0;}
This article is from the "Flower Open Shore" blog, please be sure to keep this source http://zxtong.blog.51cto.com/10697148/1703538
Two binary bit bits with different numbers