-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
28 lines (27 loc) · 679 Bytes
/
Solution.java
File metadata and controls
28 lines (27 loc) · 679 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package test;
import java.util.Scanner;
public class Solution {
/**
* 获得两个整形二进制表达位数不同的数量
*
* @param m 整数m
* @param n 整数n
* @return 整型
*/
public int countBitDiff(int m, int n) {
int temp=(m^n);
int res=0;
while(temp!=0){
res+=(temp&1);
temp=(temp>>>1);
}
return res;
}
public static void main(String[] args) {
Solution s=new Solution();
Scanner sc=new Scanner(System.in);
int m=sc.nextInt();
int n=sc.nextInt();
System.out.println(s.countBitDiff(m,n));
}
}