Skip to content

Instantly share code, notes, and snippets.

@bitcpf
Created August 4, 2014 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitcpf/a047a1ab454947052b86 to your computer and use it in GitHub Desktop.
Save bitcpf/a047a1ab454947052b86 to your computer and use it in GitHub Desktop.
public class Q5_5 {
public static void main(String[] args){
int a = 73;
int b =834;
System.out.println("Binary a is:"+Integer.toBinaryString(a));
System.out.println("Binary b is:"+Integer.toBinaryString(b));
System.out.println(bitDifference(a,b));
}
public static int bitDifference(int a, int b){
int cnt = 0;
int c = a ^ b;
while(c != 0){
cnt += c & 1;
c >>= 1;
}
return cnt;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment