Do bitwise AND between BitArray in CSharp

Description

The following code shows how to do bitwise AND between BitArray.

Example


using System;/*from   w ww .  ja  v  a 2 s  . c o  m*/
using System.Collections;
public class SamplesBitArray  {

   public static void Main()  {

      BitArray myBA1 = new BitArray( 4 );
      BitArray myBA2 = new BitArray( 4 );
      myBA1[0] = myBA1[1] = false;
      myBA1[2] = myBA1[3] = true;
      myBA2[0] = myBA2[2] = false;
      myBA2[1] = myBA2[3] = true;

      PrintValues( myBA1.And( myBA2 ) );
   }


   public static void PrintValues( IEnumerable myList)  {
      foreach ( Object obj in myList ) {
        Console.WriteLine(obj );
      }
   }

}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary