在一行上输入两个整数
,表示需要比较的两个正整数。
在一行上输出一个整数,表示
和
的二进制表示中不同的位数
。
15 8
3
在这个样例中,
的二进制为
,
的二进制为
。
从最低位对齐后比较四个二进制位,有
个位置上的数字不同,因此答案为
。
7 10
3
在这个样例中,
的二进制为
,
的二进制为
。
补齐后比较四个二进制位:
第
位(最低位):
;
第
位:
;
第
位:
;
第
位:
。
共有
个位置不同,故答案为
。
import java.util.*;
public class Main {
private static final int MAX = 1005;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n1 = sc.nextInt(), n2 = sc.nextInt();
int count = 0;
for (; n1 != 0 || n2 !=0; n1 >>= 1, n2 >>= 1) {
if ((n1 & 1) != (n2 & 1)) {
count++;
}
}
System.out.println(count);
}
}
import java.util.Scanner;
/**
* @author wylu
*/
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int xor = scanner.nextInt() ^ scanner.nextInt();
int count = 0;
while (xor != 0) {
xor &= (xor - 1);
count++;
}
System.out.println(count);
}
}
}
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=998244353;
const int N=500010;
void solve(){
int m,n;cin>>m>>n;
int x=m^n;
int ans=__builtin_popcountll(x);
cout<<ans<<"\n";
}
signed main(){
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int t=1;
// cin>>t;
while(t--){
solve();
}return 0;
} #include <stdio.h>
#include <stdlib.h>
int main(void) {
int m, n;
fscanf(stdin, "%d %d", &m, &n);
return fprintf(stdout, "%d", __builtin_popcount(m ^ n)), 0;
} using System;
using System.Collections.Generic;
public class Program {
public static void Main() {
string [] parts =Console.ReadLine().Split( );
int m = int.Parse(parts[0]);
int n=int.Parse(parts[1]);
int ans =0;
int yihuo =m^n;//异或
while(yihuo!=0){//计算异或后的结果里有多少个 1
ans += yihuo & 1;
yihuo>>=1;
}
System.Console.WriteLine(ans);
}
} System.out.println(Integer.bitCount(in.nextInt() ^ in.nextInt()));
int n; __asm__ volatile ( "XOR %%ebx,%%eax\n" "POPCNT %%eax,%%eax\n" : "=a"(n) : "a"(read_uint()), "b"(read_uint()) : "cc" ); write_uint(n);
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int result = m ^ n;
System.out.println(sumBone(result));
}
// 使用位运算求二进制中有几个1
public static int sumBone (int n) {
n = (n & 0x55555555) + (n >>> 1 & 0x55555555);
n = (n & 0x33333333) + (n >>> 2 & 0x33333333);
n = (n & 0x0f0f0f0f) + (n >>> 4 & 0x0f0f0f0f);
n = (n & 0x00ff00ff) + (n >>> 8 & 0x00ff00ff);
n = (n & 0x0000ffff) + (n >>> 16 & 0x0000ffff);
return n;
}
} #include <stdio.h>
#include <stdlib.h>
int main()
{
unsigned int x,y;
while(scanf("%d %d",&x,&y)!=EOF)
{
unsigned int temp=x^y;
int count=0;
while(temp)
{
if(temp%2)
{
count++;
}
temp/=2;
}
printf("%d\n",count);
}
return 0;
}