我必须编写一个简单的方法来接收索引并将该索引处的“位”从0
切换到1
. 我无法为此编写按位运算符。我知道这很简单,但我无法理解。下面是该方法的外观。先感谢您!
/**
* 32-bit data initialized to all zeros. Here is what you will be using to represent
* the Bit Vector.
*/
private int bits;
/** You may not add any more fields to this class other than the given one. */
/**
* Sets the bit (sets to 1) pointed to by index.
* @param index index of which bit to set.
* 0 for the least significant bit (right most bit).
* 31 for the most significant bit.
*/
public void set(int index)
{
//It is here where I can not figure it out. Thank you!
System.out.println(~bits);
System.out.println("setting bit: " + bits + " to: " + index);
}