c# - C# 中的 BitArrays 有问题吗?

标签 c# xor bitarray

当我编译这段代码时:

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/

相关文章:

c++ - 这段代码如何计算一个数的奇偶性?

java - java中异或有符号字节

.net - 计算 .Net BitArray 类中设置的位

c# - 理解调度队列

c# - 在 C# 中编译并执行外部代码

c# - NHibernate Query/QueryOver 与日期时间比较

algorithm - 找到一个数字与序列元素进行异或以获得给定的总和

c# - 将 BigInteger 变量写入 BitArray,反之亦然

算法:非常稀疏的位数组的数量巨大,要使用哪种编码

c# - Windows 应用商店应用程序 - C# - Https 客户端身份验证