How to create a bitset in VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections

Class Program
    Public Shared Sub Main()
		Dim bitArray As BitArray = New BitArray(8)
        bitArray(0) = True
        bitArray(3) = True
        
		Console.WriteLine("BitArray:")
        PrintBitArray(bitArray)
        
		bitArray.SetAll(False)
        bitArray.[Set](2, True)
        
		Console.WriteLine("Modified BitArray:")
        PrintBitArray(bitArray)
    End Sub

	Public Shared Sub PrintBitArray(ByVal bitArray As BitArray)
        For i As Integer = 0 To bitArray.Length - 1
            Console.Write(If(bitArray(i), "1", "0"))
        Next

        Console.WriteLine()
    End Sub
End Class



' run:
'
' BitArray:
' 10010000
' Modified BitArray:
' 00100000
'

 



answered May 7 by avibootz
...