BitArray bits = new BitArray(4); // Creates a new BitArray of size 4 bits[0] = true; // Sets the first bit to true (1) bits[2] = true; // Sets the third bit to true (1)
byte[] byteArray = new byte[] { 0x3, 0x5 }; // Creates a byte array BitArray bits = new BitArray(byteArray); // Creates a new BitArray from the byte array
BitArray bits1 = new BitArray(new byte[] { 0x3 }); // Creates a new BitArray with 0x3 (0011) as its value BitArray bits2 = new BitArray(new byte[] { 0x5 }); // Creates a new BitArray with 0x5 (0101) as its value // Perform bitwise AND on bits1 and bits2 BitArray andBits = new BitArray(bits1).And(bits2); // Perform bitwise OR on bits1 and bits2 BitArray orBits = new BitArray(bits1).Or(bits2); // Perform bitwise XOR on bits1 and bits2 BitArray xorBits = new BitArray(bits1).Xor(bits2);The BitArray class is part of the System.Core.dll package library.