Mono Class Library: System.Collections.BitArray Overview | Members

System.Collections.BitArray.Xor Method

Performs a bitwise Xor of two BitArray instances.

public BitArray Xor (BitArray value)

Parameters

value
The BitArray to Xor with the current instance.

Returns

A BitAray whose bit values are the bitwise Xor of the BItArray instance and the argument BitArray.

Remarks

The result of the Xor operation overwrites the original instance.

The two BitArrays must be the same length. If they are not an ArgumentException will be thrown.

C# Example

using System;
using System.Collections;
using System.Text;

        public class BitArrayXor
        {
                public static void Main ()
                {
                        BitArray leftOperand = new BitArray (new bool [] {true, false, false, true});
                        BitArray rightOperand = new BitArray (new bool [] {true, false, true, false});
                        BitArrayOut.PrintBitArray (leftOperand, " Xor ");
                        BitArrayOut.PrintBitArray (rightOperand, " = ");
                        leftOperand.Xor (rightOperand);
                        BitArrayOut.PrintBitArray (leftOperand, "\n");
                }
        }

        public static class BitArrayOut
        {
                internal static void PrintBitArray (BitArray bitArray)
                {
                        Console.Write (BitArrayToString (bitArray));
                }

                internal static void PrintBitArray (BitArray bitArray, string symbol)
                {
                        PrintBitArray (bitArray);
                        Console.Write (symbol);
                }

                private static string BitArrayToString (BitArray bitArray)
                {
                        StringBuilder stringBuilder = new StringBuilder ();
                        for (int i = bitArray.Count - 1; i > -1; i--) {
                                char digit = bitArray[i] ? '1' : '0';
                                stringBuilder.Append (digit);
                        }

                        return stringBuilder.ToString();
                }
        }
  

Compiling and running the above example generates the following output:

1001 Xor 0101 = 1100

Requirements

Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0