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

System.Collections.BitArray.Or Method

Performs a bitwise Or of two BitArray instances.

public BitArray Or (BitArray value)

Parameters

value
The BitArray to Or with the current instance.

Returns

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

Remarks

The result of the Or 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;

        public class BitArrayOr
        {
                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, " Or ");
                        BitArrayOut.PrintBitArray (rightOperand, " = ");
                        leftOperand.Or(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 Or 0101 = 1101

Requirements

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