BitArray class

bitArray_code-Vb-NET-tutorialbyte-com

BitArray

The BitArray class manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on (1) and false indicates the bit is off (0).

Thus, BitArray is  used when you need to store the bits but do not know the number of bits in advance and you can access items from the BitArray collection by using an integer index, which starts from zero.

Properties and Methods of the BitArray Class

The following table lists some of the commonly used properties of the BitArray class:

Property Description
Count Gets the number of elements contained in the BitArray.
IsReadOnly Gets a value indicating whether the BitArray is read-only.
Item Gets or sets the value of the bit at a specific position in the BitArray.
Length Gets or sets the number of elements in the BitArray.

Finally the following table lists some of the commonly used methods of the BitArray class:

S.N Method Name & Purpose
1 Public Function And (value As BitArray) As BitArray

Performs the bitwise AND operation on the elements in the current BitArray against the corresponding elements in the specified BitArray.

2 Public Function Get (index As Integer) As Boolean

Gets the value of the bit at a specific position in the BitArray.

3 Public Function Not As BitArray

Inverts all the bit values in the current BitArray, so that elements set to true are changed to false, and elements set to false are changed to true.

4 Public Function Or (value As BitArray) As BitArray

Performs the bitwise OR operation on the elements in the current BitArray against the corresponding elements in the specified BitArray.

5 Public Sub Set (index As Integer, value As Boolean )

Sets the bit at a specific position in the BitArray to the specified value.

6 Public Sub SetAll (value As Boolean)

Sets all bits in the BitArray to the specified value.

7 Public Function Xor (value As BitArray) As BitArray

Performs the bitwise eXclusive OR operation on the elements in the current BitArray against the corresponding elements in the specified BitArray.

The following example demonstrate the use of Bitarray class.

bitArray_code-Vb-NET-tutorialbyte-com bit arraybitArray_code-Vb-NET-tutorialbyte-com bit array

Leave a Reply

Your email address will not be published. Required fields are marked *