19.2. BitArray

A BitArray is similar to an ArrayList, except that it is used to store only bits represented as boolean values. A 1 bit is true, while a 0 bit is false. BitArray objects are extremely useful for mathematical operations such as those involving long encryption keys. The class has the following public methods which are useful for operations on the bits it encapsulates: Xor, Not, Or, And.

The program below demonstrates how a BitArray can be used. The output is interspersed with the code to show the outputs of the different sections.

 1: using System; 2: using System.Collections; 3: 4: public class TestClass { 5: public static void Main() { 6: 7: // By default, all bits are false if not specified 8: BitArray ba1 = new BitArray(4); 9: ...

Get From Java to C#: A Developer's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.