Skip to content

Instantly share code, notes, and snippets.

@astkaasa
Created April 16, 2013 02:01
Show Gist options
  • Save astkaasa/5392781 to your computer and use it in GitHub Desktop.
Save astkaasa/5392781 to your computer and use it in GitHub Desktop.
problem 5.5
public class BitConvertNumbers {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println( bitSwapRequired( 1089, 7 ) );
}
public static int bitSwapRequired( int a, int b ) {
int count = 0;
for ( int c = a ^ b; c != 0; c = c & ( c - 1 ) ) {
count++;
}
return count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment