LintCode - 将整数A转换为B(普通)

版权声明:本文为博主原创文章,未经博主允许不得转载。

难度:容易
要求:

如果要将整数A转换为B,需要改变多少个bit位?

样例
给出A=[1,2,3,4],B=[2,4,5,6],返回** [1,2,2,3,4,4,5,6]**

思路

   /**
     *@param a, b: Two integer
     *return: An integer
     */
    public static int bitSwapRequired(int a, int b) {
        // write your code here
        int count = 0;
        int c = a ^ b;
        while(c != 0){
            count += c & 1;
            c = c >>>1;
        }
        return count;
    }

你可能感兴趣的:(LintCode - 将整数A转换为B(普通))