Find the number of bits that needed to be flipped to convert from one number to another number - Java Quiz Question


Write a program to get number of bits that needed to be flipped to convert from one number to another number.

Input (int, int) Output (int)
2, 1 2
4, 16 2
15, 4 3
18, 16 1



class NumberOfBitsFlipped
{
    public static void main(String s[])
    {
        int fromNumber = 2, toNumber = 1;
        System.out.println("Number of bits needed to be flipped to convert " + fromNumber + " to " + toNumber + " is " + getNumberOfFlips(fromNumber, toNumber));

    }


    public static int getNumberOfFlips(int fromNumber, int toNumber) {
    }

}