Csharp/C Sharp by API/System.Collections/BitArray
Содержание
BitArray.Length
<source lang="csharp">
using System; using System.Collections; public class Example11_4 {
public static void Main() { BitArray myBitArray = new BitArray(4); Console.WriteLine("myBitArray.Length = " + myBitArray.Length); myBitArray[0] = false; myBitArray[1] = true; myBitArray[2] = true; myBitArray[3] = false; for (int counter = 0; counter < myBitArray.Count; counter++) { Console.WriteLine("myBitArray[" + counter + "] = " + myBitArray[counter]); } }
}
</source>
BitArray.Not()
<source lang="csharp"> using System; using System.Collections;
public class BADemo {
public static void showbits(string rem, BitArray bits) { Console.WriteLine(rem); for(int i=0; i < bits.Count; i++) Console.Write("{0, -6} ", bits[i]); Console.WriteLine("\n"); } public static void Main() { BitArray ba = new BitArray(8); byte[] b = { 67 }; BitArray ba2 = new BitArray(b); showbits("Original contents of ba:", ba); ba = ba.Not(); showbits("Contents of ba after Not:", ba); showbits("Contents of ba2:", ba2); BitArray ba3 = ba.Xor(ba2); showbits("Result of ba XOR ba2:", ba3); }
}
</source>
BitArray.Or
<source lang="csharp"> using System; using System.Collections; class MainClass {
public static void DisplayBitArray(string arrayListName, BitArray myBitArray ) { for (int i = 0; i < myBitArray.Count; i++) { Console.WriteLine(arrayListName + "[" + i + "] = " + myBitArray[i]); } } public static void Main() { BitArray myBitArray = new BitArray(4); myBitArray[0] = false; myBitArray[1] = true; myBitArray[2] = true; myBitArray[3] = false; DisplayBitArray("myBitArray", myBitArray); BitArray anotherBitArray = new BitArray(myBitArray); DisplayBitArray("anotherBitArray", myBitArray); myBitArray.Not(); DisplayBitArray("myBitArray", myBitArray); myBitArray.Or(anotherBitArray); DisplayBitArray("myBitArray", myBitArray);
}
}
</source>
BitArray.Xor
<source lang="csharp"> using System; using System.Collections;
public class BADemo {
public static void showbits(string rem, BitArray bits) { Console.WriteLine(rem); for(int i=0; i < bits.Count; i++) Console.Write("{0, -6} ", bits[i]); Console.WriteLine("\n"); } public static void Main() { BitArray ba = new BitArray(8); byte[] b = { 67 }; BitArray ba2 = new BitArray(b); showbits("Original contents of ba:", ba); ba = ba.Not(); showbits("Contents of ba after Not:", ba); showbits("Contents of ba2:", ba2); BitArray ba3 = ba.Xor(ba2); showbits("Result of ba XOR ba2:", ba3); }
}
</source>
new BitArray(byte[] b)
<source lang="csharp"> using System; using System.Collections;
public class BADemo {
public static void showbits(string rem, BitArray bits) { Console.WriteLine(rem); for(int i=0; i < bits.Count; i++) Console.Write("{0, -6} ", bits[i]); Console.WriteLine("\n"); } public static void Main() { BitArray ba = new BitArray(8); byte[] b = { 67 }; BitArray ba2 = new BitArray(b); showbits("Original contents of ba:", ba); ba = ba.Not(); showbits("Contents of ba after Not:", ba); showbits("Contents of ba2:", ba2); BitArray ba3 = ba.Xor(ba2); showbits("Result of ba XOR ba2:", ba3); }
}
</source>
new BitArray(int size)
<source lang="csharp"> using System; using System.Collections;
public class BADemo {
public static void showbits(string rem, BitArray bits) { Console.WriteLine(rem); for(int i=0; i < bits.Count; i++) Console.Write("{0, -6} ", bits[i]); Console.WriteLine("\n"); } public static void Main() { BitArray ba = new BitArray(8); byte[] b = { 67 }; BitArray ba2 = new BitArray(b); showbits("Original contents of ba:", ba); ba = ba.Not(); showbits("Contents of ba after Not:", ba); showbits("Contents of ba2:", ba2); BitArray ba3 = ba.Xor(ba2); showbits("Result of ba XOR ba2:", ba3); }
}
</source>