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

System.Collections.BitArray.Not Method

Negates all of the bits in a BitArray.

public BitArray Not ()

Returns

A BitAray whose bit values are the negation of the BItArray instance.

Remarks

The result of the Not operation overwrites the original instance.

C# Example

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

        public class BitArrayNot
        {
                public static void Main ()
                {
                        BitArray bitArray = new BitArray (new bool [] {true, false, false, true});
                        Console.Write ("bitArray:       ");
                        BitArrayOut.PrintBitArray (bitArray, "\n");
                        Console.Write ("bitArray.Not(): ");
                        bitArray.Not ();
                        BitArrayOut.PrintBitArray (bitArray, "\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:

bitArray: 1001

bitArray.Not(): 0110

Requirements

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