Created
April 16, 2013 02:01
-
-
Save astkaasa/5392781 to your computer and use it in GitHub Desktop.
problem 5.5
This file contains 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
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