BitArray Class manages a compact array of bit values : BitArray « Collections Data Structure « C# / C Sharp






BitArray Class manages a compact array of bit values

 

using System;
using System.Collections;
public class SamplesBitArray  {

   public static void Main()  {
      // Creates and initializes several BitArrays.
      BitArray myBA1 = new BitArray( 5 );
      BitArray myBA2 = new BitArray( 5, false );
      byte[] myBytes = new byte[5] { 1, 2, 3, 4, 5 };
      BitArray myBA3 = new BitArray( myBytes );
      bool[] myBools = new bool[5] { true, false, true, true, false };
      BitArray myBA4 = new BitArray( myBools );
      int[]  myInts  = new int[5] { 6, 7, 8, 9, 10 };
      BitArray myBA5 = new BitArray( myInts );

   }

   public static void PrintValues( IEnumerable myList, int myWidth )  {
      int i = myWidth;
      foreach ( Object obj in myList ) {
         if ( i <= 0 )  {
            i = myWidth;
            Console.WriteLine();
         }
         i--;
         Console.Write( "{0,8}", obj );
      }
      Console.WriteLine();
   }

}

   
  








Related examples in the same category

1.Demonstrate BitArrayDemonstrate BitArray
2.Use BitArray collection as Flag
3.illustrates the use of a BitArrayillustrates the use of a BitArray
4.illustrates the use of BitArray methodsillustrates the use of BitArray methods
5.Displays the properties and values of the BitArrays
6.BitArray.CopyTo copies the entire BitArray to a compatible one-dimensional Array
7.Gets the value of the bit at a specific position in the BitArray.
8.Inverts all the bit values in the current BitArray
9.Performs the bitwise OR operation
10.Performing OR between BitArray instances of different sizes returns an exception
11.Performs bitwise exclusive OR operation