当我编译这段代码时:
BitArray bits = new BitArray(3);
bits[0] = true;
bits[1] = true;
bits[2] = true;
BitArray moreBits = new BitArray(3);
bits[0] = true;
bits[1] = true;
bits[2] = true;
BitArray xorBits = bits.Xor(moreBits);
foreach (bool bit in xorBits)
{
Console.WriteLine(bit);
}
我得到以下输出:
True True True
当我通过说 true ^ true 对两个 bool 值进行异或时,我得到 false。
是不是代码有问题。我对 XOR 真值表的内存是 True XOR True 为假。
最佳答案
复制粘贴错误。
BitArray moreBits = new BitArray(3);
bits[0] = true;
bits[1] = true;
bits[2] = true;
应该是:
BitArray moreBits = new BitArray(3);
moreBits[0] = true;
moreBits[1] = true;
moreBits[2] = true;
关于c# - C# 中的 BitArrays 有问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/638524/