bitwise xor is giving the wrong result

T

Tony Johansson

Hi!

How on earth can the result on xorbits be true when you are doing an xor
between two
bits where each bit is true it should be false ?

public void Main(string[] args)
{
BitArray bits = new BitArray(1);
bits[0] = true;

BitArray morebits = new BitArray(1);
bits[0] = true;

BitArray xorbits = bits.Xor(morebits);

foreach (bool bit in xorbits)
Console.WriteLine(bit);
}

//Tony
 
W

Willem van Rumpt

Tony said:
Hi!

How on earth can the result on xorbits be true when you are doing an xor
between two
bits where each bit is true it should be false ?

Because you mistakenly initialized bits[0] to true twice, leaving
morebits[0] initialized to false, resulting in the evaluation
false xor true
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top