Count number of bits to be flipped to convert A to B | Count number of bits to be flipped to convert A into B ; Function that count set bits ; Function that return count of flipped number ; Return count of set bits in a XOR b ; Driver code
import java . util . * ; class Count { public static int countSetBits ( int n ) { int count = 0 ; while ( n != 0 ) { count ++ ; n &= ( n - 1 ) ; } return count ; } public static int FlippedCount ( int a , int b ) { return countSetBits ( a ^ b ) ; } public static void main ( String [ ] args ) { int a = 10 ; int b = 20 ; System . out . print ( FlippedCount ( a , b ) ) ; } }