lintcode:将整数A转换为B

xiaoxiao2021-02-28  85

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

 注意事项

Both n and m are 32-bit integers.

class Solution { public: /** *@param a, b: Two integer *return: An integer */ int bitSwapRequired(int a, int b) { // write your code here int c = a^b; int count = 0; for(int i = 0;i < 32;i++) { if(c >> i & 0x01) { count ++; } } return count; } };

转载请注明原文地址: https://www.6miu.com/read-70465.html

最新回复(0)