Created
July 26, 2014 15:27
-
-
Save WOLOHAHA/680263a54d25f4495d54 to your computer and use it in GitHub Desktop.
Write a function to determine the number of bits required to convert integer A to integer B.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package POJ; | |
| public class Main{ | |
| /** | |
| * | |
| * 5.5 Write a function to determine the number of bits required to convert integer A to integer B. | |
| * | |
| * | |
| */ | |
| public int bitSwapRequired(int a, int b){ | |
| int count=0; | |
| for(int c=a^b;c!=0;c>>=1){ | |
| count+=c&1; | |
| } | |
| return count; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment