Return Y integer with same bit sets as X & having | X - Y | minimum value
Your algorithm is logical, but a little trick can make it much simpler too. Because applying the trick makes the code so much shorter, it seems better to just point out some smaller issues in your code, and then show the improved algorithm later....

So, first up.... the method name: MinDiff .... really? Java convention is to have camelCase method names, not PascalCase. The first letter should be a lower-case.

Your variable names also are horrible.... y, x, a, and b. With x and y variables I am always looking for cartesian coordinates or something. Choose more meaningful names.

Your handling of 0 and -1 is also broken. Since there are no bits set in 0, and no unset bits in -1, they are impossible to provide a solution for, so the best thing would be to handle them as exceptions. Returning -1 for an input of 0 is broken, and overflowing on the input of -1 is inconsistent too.

So, having said that, the best algorithm to use is to identify the right-most change in bit values... where bitn and bitn-1 are different. Then, just swap them. A swap is easy to do with and XOR:

public static final int leastBitFlip(final int input) {
    if (input == 0 || input == -1) {
        throw new IllegalArgumentException("0 or -1 are not possible to compute as inputs");
    }
    int mask = 0b11;
    while (sameBits(input, mask)) {
        mask &lt;&lt;= 1;
    }
    // swap the bits.
    return input ^ mask;
}

private static boolean sameBits(final int input, final int mask) {
    final int bits = input &amp; mask;
    final int swap = mask &amp; ((bits &lt;&lt; 1) | (bits &gt;&gt; 1));
    return bits == swap;
}


Now, as for determining whether two bits are the same, or not, I think that sameBits() function can be improved, but I have not really run the truth table on it. The code is simple enough to understand though, and readability is important in these things.

Using the hint from ErikR - this algorithm would be faster though too:

public static final int leastBitFlip(int input) {
    if (input == 0 || input == -1) {
        throw new IllegalArgumentException("0 or -1 are not possible to compute as inputs");
    }
    // right-most one-bit.
    int onebit = ((input ^ (input - 1)) + 1) &gt;&gt; 1;
    // right most zero-bit.
    int zerobit = ((input ^ (input + 1)) + 1) &gt;&gt; 1;
    // where the change happens
    int change = onebit &gt; zerobit ? onebit : zerobit;
    // create a mask of the two bits either side of the change.
    int mask = change | (change &gt;&gt; 1);
    // swap them
    return input ^ mask;
}