Skip to content

Instantly share code, notes, and snippets.

@WOLOHAHA
Created July 26, 2014 15:27
Show Gist options
  • Select an option

  • Save WOLOHAHA/680263a54d25f4495d54 to your computer and use it in GitHub Desktop.

Select an option

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.
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