reference:
http://www.geeksforgeeks.org/count-number-of-bits-to-be-flipped-to-convert-a-to-b/
Problem Definition:
You are given two numbers A and B. Write a program to count number of bits needed to be flipped to convert A to B.
Solution:
1. Calculate XOR of A and B. a_xor_b = A ^ B 2. Count the set bits in the above calculated XOR result. countSetBits(a_xor_b)
本文介绍了一种计算两个整数间需要翻转多少位才能互相转换的方法。通过计算两数的异或值并统计其中1的个数,即可得到答案。
2246

被折叠的 条评论
为什么被折叠?



