Task:
Implement the flipBit method, which changes the value of one bit of a given integer to the opposite. This task is relevant, for example, when working with bit fields.
We agree that the bits are numbered from the youngest (index 1) to the oldest (index 32).
Sample I / O:
Sample Input: 0 1 Sample Output: 1
My decision:
public static int flipBit(int value, int bitIndex) { return value ^ bitIndex; // put your implementation here }
What is wrong with my decision? Checked on BitwiseCmd . It seems everything is correct.