Mega Code Archive

 
Categories / C# / Collections Data Structure
 

Inverts all the bit values in the current BitArray

using System; 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;       myBA1.Not();       myBA2.Not();       PrintValues( myBA1, 8 );       PrintValues( myBA2, 8 );    }    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 );       }    } }