Hi ...
I read this question in one magzine.
2 ints A and B are given, find the no of bits that need to be flipped in A to get B.
Can any one tell me how to solve this....
Thanks in advance.
This is a discussion on Any Idea ...please help within the Tech Board forums, part of the Community Boards category; Hi ... I read this question in one magzine. 2 ints A and B are given, find the no of ...
Hi ...
I read this question in one magzine.
2 ints A and B are given, find the no of bits that need to be flipped in A to get B.
Can any one tell me how to solve this....
Thanks in advance.
Kindly do not cross post. Since I could not determine whether you intended it to be C, C++ or just a question of an algorithm, it has been moved to the Tech board.
Here's one possible algorithm: set a counter to 0. Start from the first bit of A, and compare it with the first bit of B. If the bits are different, increment the counter. Repeat for the remaining bits.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
It's the number of 1's in A XOR B.
How about xor the two ints, then count the 1 bits in the result. (just as an alternative).
Visit entropysink.com - It's what your PC is made for!
Beat me to it![]()
Visit entropysink.com - It's what your PC is made for!