Created
August 4, 2014 19:55
-
-
Save bitcpf/a047a1ab454947052b86 to your computer and use it in GitHub Desktop.
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 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