java中的"| ="和"^ ="是什么意思?

Kee*_*tan 5 java

这是用于改变图像的比特值的功能.是什么|=^=意味着什么呢?

private int setBitValue(int n,int location,int bit)  {
    int toggle=(int)Math.pow(2,location),bv=getBitValue(n,location);
    if(bv==bit)
       return n;
    if(bv==0 && bit==1)
       n|=toggle;        // what does it do?
    else if(bv==1 && bit==0)
       n^=toggle;        // what does it do?

    return n;
}
Run Code Online (Sandbox Code Playgroud)

Mik*_*her 4

它的缩写形式与 += 相同

n |= toogle
Run Code Online (Sandbox Code Playgroud)

是相同的

n = n | toogle
Run Code Online (Sandbox Code Playgroud)

| 的 | 这里是二元或运算符,^ 是二元异或运算符