1/* determine how many digits need to be changed before integer A can be converted to integer B 2 * Identify the differences between two digits, you can use an exclusive or operation to 3 * view the result of an exclusive or operation, each 1 indicates that the corresponding bits of A and B are not the same 4 *. Therefore, as long as the number of digits is different or the number of digits is 1, you can know that you need to change the number of digits 5*6 **/ 7 public class bitsnum {8 Public int bitswaprequired (int, int B) 9 {10 int COUNT = 0; 11 for (INT c = a ^ B; C! = 0; C = C> 1) 12 {13 count + = C & 1; 14} 15 return count; 16} 17 18 public static void main (string [] ARGs) {19 // todo auto-generated method stub20 bitsnum bit = new bitsnum (); 21 int num = bit. bitswaprequired (2, 4); 22 system. out. println (Num); 23} 24 25}
Determine how many digits need to be changed before integer A can be converted to integer B.