#include <stdio.h>
#define MAX (x, y) < (y)? ( X):(Y))
int main ()
{
int a
= 1999;
int b = 2299;
int num = 1;
int nam;
if (b% 2 = = 1)
{
NAM = 1;
}
Else
{
Nam = 0;
}
Do
{
int A = a% 2;
int B = b% 2;
if (A! = B)
{
num++;
}
Else
{
num = num;
}
A = A/2;
b = B/2;
}while (B!=nam);
printf ("%d", num);
}
Method two;
#include <stdio.h>
#define MAX (x, y) > (y)? ( X):(Y))
int num_sing (int max)
{
if (max% 2 = = 0)
{
return 0;
}
Else
{
return 1;
}
}
int main ()
{
int a = 1999;
int b = 2299;
int i = 0;
int num = 0;
int max = Max (A, b);
int sing = num_sing (MAX (A, b));
int Cishu =0+sing;
while (max!= sing)
{
max = MAX/2;
cishu++;
}
for (i = 0; i < Cishu; i++)
{
if ((a&1)! = (b&1))
{
num++;
}
A = a >> 1;
b = b >> 1;
}
printf ("%d", num);
}
This article is from the "Traces" blog, be sure to keep this source http://wpfbcr.blog.51cto.com/10696766/1703379
Find out how many bit bits differ in binary representations of two int (32-bit) integers m and n