home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / dotNETSDK / SETUP.EXE / netfxsd1.cab / FL_IndexProperty_vb________.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Encoding:
Text File  |  2001-08-21  |  1.9 KB  |  61 lines

  1. 
  2. Imports System
  3. Imports System.Collections
  4. Imports Microsoft.VisualBasic
  5.  
  6.  
  7.  
  8. Class BitArray
  9.     Private numBits As Int32
  10.     Private bytearray() As Byte
  11.     
  12.     
  13.     Public Sub New(numBits As Int32)
  14.         Me.numBits = numBits
  15.         bytearray = New Byte(CType((numBits + 7) / 8, Integer)) {}
  16.     End Sub 'New
  17.     
  18.     
  19.     Default Public Property Item(bit As Int32) As Boolean
  20.         Get
  21.             If bit < 0 Or bit >= numBits Then
  22.                 Throw New ArgumentOutOfRangeException("bit must be between 0 and " & numBits)
  23.             End If
  24.             Return (bytearray(CInt(Conversion.Fix(bit / 8))) And CLng(Math.Pow (2, bit Mod 8))) <> 0
  25.         End Get
  26.         Set
  27.             If bit < 0 Or bit >= numBits Then
  28.                 Throw New ArgumentOutOfRangeException("bit must be between 0 and " & numBits)
  29.             End If
  30.             If value Then
  31.                 bytearray(CInt(Conversion.Fix(bit / 8))) = CType(bytearray(CInt(Conversion.Fix(bit / 8))) Or CLng(Math.Pow (2, bit Mod 8)), [Byte])
  32.             Else
  33.                 bytearray(CInt(Conversion.Fix(bit / 8))) = CType(bytearray(CInt(Conversion.Fix(bit / 8))) And Not CLng(Math.Pow (2, bit Mod 8)), [Byte])
  34.             End If
  35.         End Set
  36.     End Property
  37. End Class 'BitArray
  38.  
  39.  
  40.  
  41. Class App
  42.     
  43.     Shared Sub Main()
  44.         Dim ba As New BitArray(14)
  45.         Dim bit As Integer
  46.         For bit = 0 To 13
  47.             ' Set the first 7 bits to On, the rest to Off
  48.             ba(bit) = bit < 7
  49.         Next bit
  50.         
  51.         Dim bitstate As String
  52.         For bit = 0 To 13
  53.             ' Show the value of each bit in the array
  54.             If ba(bit) Then bitstate = "On" Else bitstate = "Off"
  55.             Console.WriteLine("Bit {0} is {1}", bit, bitstate)
  56.         Next bit
  57.  
  58.         Console.Write("Press Enter to close window...")
  59.         Console.Read()
  60.     End Sub 'Main
  61. End Class 'App