package bd_algo;
public class bit_tran {
public static void main(String[] args) {
System.out.println(bitSwapRequired(1, -1));
}
public static int bitSwapRequired(int a, int b) {
int tmp = a ^ b;
int sum = 0;
while (tmp!= 0){
System.out.println(tmp + " : " + Integer.toBinaryString(tmp));
System.out.println(tmp - 1 + " : " + Integer.toBinaryString(tmp - 1));
tmp = tmp & (tmp - 1);
System.out.println(tmp + " : " + Integer.toBinaryString(tmp));
System.out.println("------------------");
sum++;
}
return sum;
}
}
05-07
05-07
05-07
05-07
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交