document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. Namespace TizzyT
  2.     Public Class BitList
  3.         Private Bits As List(Of Byte)
  4.         Private ByteValue As Byte = 0
  5.         Private Pos As Byte = 0
  6.         Private Shared ReadOnly Table(,) As Boolean =
  7.             {{0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 1},
  8.              {0, 0, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 1}, {0, 0, 0, 0, 0, 1, 1, 0}, {0, 0, 0, 0, 0, 1, 1, 1},
  9.              {0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 1}, {0, 0, 0, 0, 1, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 1, 1},
  10.              {0, 0, 0, 0, 1, 1, 0, 0}, {0, 0, 0, 0, 1, 1, 0, 1}, {0, 0, 0, 0, 1, 1, 1, 0}, {0, 0, 0, 0, 1, 1, 1, 1},
  11.              {0, 0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 1}, {0, 0, 0, 1, 0, 0, 1, 0}, {0, 0, 0, 1, 0, 0, 1, 1},
  12.              {0, 0, 0, 1, 0, 1, 0, 0}, {0, 0, 0, 1, 0, 1, 0, 1}, {0, 0, 0, 1, 0, 1, 1, 0}, {0, 0, 0, 1, 0, 1, 1, 1},
  13.              {0, 0, 0, 1, 1, 0, 0, 0}, {0, 0, 0, 1, 1, 0, 0, 1}, {0, 0, 0, 1, 1, 0, 1, 0}, {0, 0, 0, 1, 1, 0, 1, 1},
  14.              {0, 0, 0, 1, 1, 1, 0, 0}, {0, 0, 0, 1, 1, 1, 0, 1}, {0, 0, 0, 1, 1, 1, 1, 0}, {0, 0, 0, 1, 1, 1, 1, 1},
  15.              {0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 1}, {0, 0, 1, 0, 0, 0, 1, 0}, {0, 0, 1, 0, 0, 0, 1, 1},
  16.              {0, 0, 1, 0, 0, 1, 0, 0}, {0, 0, 1, 0, 0, 1, 0, 1}, {0, 0, 1, 0, 0, 1, 1, 0}, {0, 0, 1, 0, 0, 1, 1, 1},
  17.              {0, 0, 1, 0, 1, 0, 0, 0}, {0, 0, 1, 0, 1, 0, 0, 1}, {0, 0, 1, 0, 1, 0, 1, 0}, {0, 0, 1, 0, 1, 0, 1, 1},
  18.              {0, 0, 1, 0, 1, 1, 0, 0}, {0, 0, 1, 0, 1, 1, 0, 1}, {0, 0, 1, 0, 1, 1, 1, 0}, {0, 0, 1, 0, 1, 1, 1, 1},
  19.              {0, 0, 1, 1, 0, 0, 0, 0}, {0, 0, 1, 1, 0, 0, 0, 1}, {0, 0, 1, 1, 0, 0, 1, 0}, {0, 0, 1, 1, 0, 0, 1, 1},
  20.              {0, 0, 1, 1, 0, 1, 0, 0}, {0, 0, 1, 1, 0, 1, 0, 1}, {0, 0, 1, 1, 0, 1, 1, 0}, {0, 0, 1, 1, 0, 1, 1, 1},
  21.              {0, 0, 1, 1, 1, 0, 0, 0}, {0, 0, 1, 1, 1, 0, 0, 1}, {0, 0, 1, 1, 1, 0, 1, 0}, {0, 0, 1, 1, 1, 0, 1, 1},
  22.              {0, 0, 1, 1, 1, 1, 0, 0}, {0, 0, 1, 1, 1, 1, 0, 1}, {0, 0, 1, 1, 1, 1, 1, 0}, {0, 0, 1, 1, 1, 1, 1, 1},
  23.              {0, 1, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 1}, {0, 1, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 1, 1},
  24.              {0, 1, 0, 0, 0, 1, 0, 0}, {0, 1, 0, 0, 0, 1, 0, 1}, {0, 1, 0, 0, 0, 1, 1, 0}, {0, 1, 0, 0, 0, 1, 1, 1},
  25.              {0, 1, 0, 0, 1, 0, 0, 0}, {0, 1, 0, 0, 1, 0, 0, 1}, {0, 1, 0, 0, 1, 0, 1, 0}, {0, 1, 0, 0, 1, 0, 1, 1},
  26.              {0, 1, 0, 0, 1, 1, 0, 0}, {0, 1, 0, 0, 1, 1, 0, 1}, {0, 1, 0, 0, 1, 1, 1, 0}, {0, 1, 0, 0, 1, 1, 1, 1},
  27.              {0, 1, 0, 1, 0, 0, 0, 0}, {0, 1, 0, 1, 0, 0, 0, 1}, {0, 1, 0, 1, 0, 0, 1, 0}, {0, 1, 0, 1, 0, 0, 1, 1},
  28.              {0, 1, 0, 1, 0, 1, 0, 0}, {0, 1, 0, 1, 0, 1, 0, 1}, {0, 1, 0, 1, 0, 1, 1, 0}, {0, 1, 0, 1, 0, 1, 1, 1},
  29.              {0, 1, 0, 1, 1, 0, 0, 0}, {0, 1, 0, 1, 1, 0, 0, 1}, {0, 1, 0, 1, 1, 0, 1, 0}, {0, 1, 0, 1, 1, 0, 1, 1},
  30.              {0, 1, 0, 1, 1, 1, 0, 0}, {0, 1, 0, 1, 1, 1, 0, 1}, {0, 1, 0, 1, 1, 1, 1, 0}, {0, 1, 0, 1, 1, 1, 1, 1},
  31.              {0, 1, 1, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 0, 1}, {0, 1, 1, 0, 0, 0, 1, 0}, {0, 1, 1, 0, 0, 0, 1, 1},
  32.              {0, 1, 1, 0, 0, 1, 0, 0}, {0, 1, 1, 0, 0, 1, 0, 1}, {0, 1, 1, 0, 0, 1, 1, 0}, {0, 1, 1, 0, 0, 1, 1, 1},
  33.              {0, 1, 1, 0, 1, 0, 0, 0}, {0, 1, 1, 0, 1, 0, 0, 1}, {0, 1, 1, 0, 1, 0, 1, 0}, {0, 1, 1, 0, 1, 0, 1, 1},
  34.              {0, 1, 1, 0, 1, 1, 0, 0}, {0, 1, 1, 0, 1, 1, 0, 1}, {0, 1, 1, 0, 1, 1, 1, 0}, {0, 1, 1, 0, 1, 1, 1, 1},
  35.              {0, 1, 1, 1, 0, 0, 0, 0}, {0, 1, 1, 1, 0, 0, 0, 1}, {0, 1, 1, 1, 0, 0, 1, 0}, {0, 1, 1, 1, 0, 0, 1, 1},
  36.              {0, 1, 1, 1, 0, 1, 0, 0}, {0, 1, 1, 1, 0, 1, 0, 1}, {0, 1, 1, 1, 0, 1, 1, 0}, {0, 1, 1, 1, 0, 1, 1, 1},
  37.              {0, 1, 1, 1, 1, 0, 0, 0}, {0, 1, 1, 1, 1, 0, 0, 1}, {0, 1, 1, 1, 1, 0, 1, 0}, {0, 1, 1, 1, 1, 0, 1, 1},
  38.              {0, 1, 1, 1, 1, 1, 0, 0}, {0, 1, 1, 1, 1, 1, 0, 1}, {0, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1},
  39.              {1, 0, 0, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 1, 0}, {1, 0, 0, 0, 0, 0, 1, 1},
  40.              {1, 0, 0, 0, 0, 1, 0, 0}, {1, 0, 0, 0, 0, 1, 0, 1}, {1, 0, 0, 0, 0, 1, 1, 0}, {1, 0, 0, 0, 0, 1, 1, 1},
  41.              {1, 0, 0, 0, 1, 0, 0, 0}, {1, 0, 0, 0, 1, 0, 0, 1}, {1, 0, 0, 0, 1, 0, 1, 0}, {1, 0, 0, 0, 1, 0, 1, 1},
  42.              {1, 0, 0, 0, 1, 1, 0, 0}, {1, 0, 0, 0, 1, 1, 0, 1}, {1, 0, 0, 0, 1, 1, 1, 0}, {1, 0, 0, 0, 1, 1, 1, 1},
  43.              {1, 0, 0, 1, 0, 0, 0, 0}, {1, 0, 0, 1, 0, 0, 0, 1}, {1, 0, 0, 1, 0, 0, 1, 0}, {1, 0, 0, 1, 0, 0, 1, 1},
  44.              {1, 0, 0, 1, 0, 1, 0, 0}, {1, 0, 0, 1, 0, 1, 0, 1}, {1, 0, 0, 1, 0, 1, 1, 0}, {1, 0, 0, 1, 0, 1, 1, 1},
  45.              {1, 0, 0, 1, 1, 0, 0, 0}, {1, 0, 0, 1, 1, 0, 0, 1}, {1, 0, 0, 1, 1, 0, 1, 0}, {1, 0, 0, 1, 1, 0, 1, 1},
  46.              {1, 0, 0, 1, 1, 1, 0, 0}, {1, 0, 0, 1, 1, 1, 0, 1}, {1, 0, 0, 1, 1, 1, 1, 0}, {1, 0, 0, 1, 1, 1, 1, 1},
  47.              {1, 0, 1, 0, 0, 0, 0, 0}, {1, 0, 1, 0, 0, 0, 0, 1}, {1, 0, 1, 0, 0, 0, 1, 0}, {1, 0, 1, 0, 0, 0, 1, 1},
  48.              {1, 0, 1, 0, 0, 1, 0, 0}, {1, 0, 1, 0, 0, 1, 0, 1}, {1, 0, 1, 0, 0, 1, 1, 0}, {1, 0, 1, 0, 0, 1, 1, 1},
  49.              {1, 0, 1, 0, 1, 0, 0, 0}, {1, 0, 1, 0, 1, 0, 0, 1}, {1, 0, 1, 0, 1, 0, 1, 0}, {1, 0, 1, 0, 1, 0, 1, 1},
  50.              {1, 0, 1, 0, 1, 1, 0, 0}, {1, 0, 1, 0, 1, 1, 0, 1}, {1, 0, 1, 0, 1, 1, 1, 0}, {1, 0, 1, 0, 1, 1, 1, 1},
  51.              {1, 0, 1, 1, 0, 0, 0, 0}, {1, 0, 1, 1, 0, 0, 0, 1}, {1, 0, 1, 1, 0, 0, 1, 0}, {1, 0, 1, 1, 0, 0, 1, 1},
  52.              {1, 0, 1, 1, 0, 1, 0, 0}, {1, 0, 1, 1, 0, 1, 0, 1}, {1, 0, 1, 1, 0, 1, 1, 0}, {1, 0, 1, 1, 0, 1, 1, 1},
  53.              {1, 0, 1, 1, 1, 0, 0, 0}, {1, 0, 1, 1, 1, 0, 0, 1}, {1, 0, 1, 1, 1, 0, 1, 0}, {1, 0, 1, 1, 1, 0, 1, 1},
  54.              {1, 0, 1, 1, 1, 1, 0, 0}, {1, 0, 1, 1, 1, 1, 0, 1}, {1, 0, 1, 1, 1, 1, 1, 0}, {1, 0, 1, 1, 1, 1, 1, 1},
  55.              {1, 1, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 0, 0, 0, 1}, {1, 1, 0, 0, 0, 0, 1, 0}, {1, 1, 0, 0, 0, 0, 1, 1},
  56.              {1, 1, 0, 0, 0, 1, 0, 0}, {1, 1, 0, 0, 0, 1, 0, 1}, {1, 1, 0, 0, 0, 1, 1, 0}, {1, 1, 0, 0, 0, 1, 1, 1},
  57.              {1, 1, 0, 0, 1, 0, 0, 0}, {1, 1, 0, 0, 1, 0, 0, 1}, {1, 1, 0, 0, 1, 0, 1, 0}, {1, 1, 0, 0, 1, 0, 1, 1},
  58.              {1, 1, 0, 0, 1, 1, 0, 0}, {1, 1, 0, 0, 1, 1, 0, 1}, {1, 1, 0, 0, 1, 1, 1, 0}, {1, 1, 0, 0, 1, 1, 1, 1},
  59.              {1, 1, 0, 1, 0, 0, 0, 0}, {1, 1, 0, 1, 0, 0, 0, 1}, {1, 1, 0, 1, 0, 0, 1, 0}, {1, 1, 0, 1, 0, 0, 1, 1},
  60.              {1, 1, 0, 1, 0, 1, 0, 0}, {1, 1, 0, 1, 0, 1, 0, 1}, {1, 1, 0, 1, 0, 1, 1, 0}, {1, 1, 0, 1, 0, 1, 1, 1},
  61.              {1, 1, 0, 1, 1, 0, 0, 0}, {1, 1, 0, 1, 1, 0, 0, 1}, {1, 1, 0, 1, 1, 0, 1, 0}, {1, 1, 0, 1, 1, 0, 1, 1},
  62.              {1, 1, 0, 1, 1, 1, 0, 0}, {1, 1, 0, 1, 1, 1, 0, 1}, {1, 1, 0, 1, 1, 1, 1, 0}, {1, 1, 0, 1, 1, 1, 1, 1},
  63.              {1, 1, 1, 0, 0, 0, 0, 0}, {1, 1, 1, 0, 0, 0, 0, 1}, {1, 1, 1, 0, 0, 0, 1, 0}, {1, 1, 1, 0, 0, 0, 1, 1},
  64.              {1, 1, 1, 0, 0, 1, 0, 0}, {1, 1, 1, 0, 0, 1, 0, 1}, {1, 1, 1, 0, 0, 1, 1, 0}, {1, 1, 1, 0, 0, 1, 1, 1},
  65.              {1, 1, 1, 0, 1, 0, 0, 0}, {1, 1, 1, 0, 1, 0, 0, 1}, {1, 1, 1, 0, 1, 0, 1, 0}, {1, 1, 1, 0, 1, 0, 1, 1},
  66.              {1, 1, 1, 0, 1, 1, 0, 0}, {1, 1, 1, 0, 1, 1, 0, 1}, {1, 1, 1, 0, 1, 1, 1, 0}, {1, 1, 1, 0, 1, 1, 1, 1},
  67.              {1, 1, 1, 1, 0, 0, 0, 0}, {1, 1, 1, 1, 0, 0, 0, 1}, {1, 1, 1, 1, 0, 0, 1, 0}, {1, 1, 1, 1, 0, 0, 1, 1},
  68.              {1, 1, 1, 1, 0, 1, 0, 0}, {1, 1, 1, 1, 0, 1, 0, 1}, {1, 1, 1, 1, 0, 1, 1, 0}, {1, 1, 1, 1, 0, 1, 1, 1},
  69.              {1, 1, 1, 1, 1, 0, 0, 0}, {1, 1, 1, 1, 1, 0, 0, 1}, {1, 1, 1, 1, 1, 0, 1, 0}, {1, 1, 1, 1, 1, 0, 1, 1},
  70.              {1, 1, 1, 1, 1, 1, 0, 0}, {1, 1, 1, 1, 1, 1, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 0}, {1, 1, 1, 1, 1, 1, 1, 1}}
  71.  
  72.         Private Shared ReadOnly ReverseByteBits() As Byte =
  73.             {0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240,
  74.              8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248,
  75.              4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244,
  76.              12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
  77.              2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
  78.              10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
  79.              6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
  80.              14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
  81.              1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241,
  82.              9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249,
  83.              5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245,
  84.              13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253,
  85.              3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243,
  86.              11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
  87.              7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
  88.              15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255}
  89.  
  90.         Default Public Property Bit(ByVal Index As Integer) As Boolean
  91.             Get
  92.                 If Index > Count() - 1 OrElse Index < 0 Then Throw New IndexOutOfRangeException()
  93.                 Dim posMain As Integer = (Index / 8) - 0.4
  94.                 Dim bitIn As Integer = Index Mod 8
  95.                 If posMain = Bits.Count Then Return Table(ByteValue, bitIn)
  96.                 Return Table(Bits(posMain), bitIn)
  97.             End Get
  98.             Set(value As Boolean)
  99.                 If Index > Count() - 1 Then Throw New IndexOutOfRangeException()
  100.                 Dim posMain As Integer = (Index / 8) - 0.4
  101.                 Dim bitIn As Integer = Index Mod 8
  102.                 If posMain = Bits.Count Then
  103.                     If Not value = Table(ByteValue, bitIn) Then
  104.                         Select Case bitIn
  105.                             Case 0 : ByteValue = ByteValue Xor 128
  106.                             Case 1 : ByteValue = ByteValue Xor 64
  107.                             Case 2 : ByteValue = ByteValue Xor 32
  108.                             Case 3 : ByteValue = ByteValue Xor 16
  109.                             Case 4 : ByteValue = ByteValue Xor 8
  110.                             Case 5 : ByteValue = ByteValue Xor 4
  111.                             Case 6 : ByteValue = ByteValue Xor 2
  112.                             Case 7 : ByteValue = ByteValue Xor 1
  113.                         End Select
  114.                     End If
  115.                 Else
  116.                     Dim B As Integer = Bits(posMain)
  117.                     If Not value = Table(B, bitIn) Then
  118.                         Select Case bitIn
  119.                             Case 0 : Bits(posMain) = B Xor 128
  120.                             Case 1 : Bits(posMain) = B Xor 64
  121.                             Case 2 : Bits(posMain) = B Xor 32
  122.                             Case 3 : Bits(posMain) = B Xor 16
  123.                             Case 4 : Bits(posMain) = B Xor 8
  124.                             Case 5 : Bits(posMain) = B Xor 4
  125.                             Case 6 : Bits(posMain) = B Xor 2
  126.                             Case 7 : Bits(posMain) = B Xor 1
  127.                         End Select
  128.                     End If
  129.                 End If
  130.             End Set
  131.         End Property
  132.  
  133.         Public Sub New()
  134.             Bits = New List(Of Byte)
  135.         End Sub
  136.  
  137.         Public Sub New(ByVal Length As Integer)
  138.             Bits = New List(Of Byte)(New Byte(CInt(Length / 8) - 1.4) {})
  139.             Pos = Length Mod 8
  140.         End Sub
  141.  
  142.         Public Sub New(ByVal Bytes() As Byte)
  143.             Bits = Bytes.ToList
  144.         End Sub
  145.  
  146.         Public Sub Add(ByVal Bit As Boolean)
  147.             If Bit Then
  148.                 Select Case Pos
  149.                     Case 0 : ByteValue = ByteValue Xor 128 : Pos += 1
  150.                     Case 1 : ByteValue = ByteValue Xor 64 : Pos += 1
  151.                     Case 2 : ByteValue = ByteValue Xor 32 : Pos += 1
  152.                     Case 3 : ByteValue = ByteValue Xor 16 : Pos += 1
  153.                     Case 4 : ByteValue = ByteValue Xor 8 : Pos += 1
  154.                     Case 5 : ByteValue = ByteValue Xor 4 : Pos += 1
  155.                     Case 6 : ByteValue = ByteValue Xor 2 : Pos += 1
  156.                     Case 7
  157.                         ByteValue = ByteValue Xor 1
  158.                         Bits.Add(ByteValue)
  159.                         ByteValue = 0
  160.                         Pos = 0
  161.                 End Select
  162.             Else
  163.                 If Pos = 7 Then
  164.                     Bits.Add(ByteValue)
  165.                     ByteValue = 0
  166.                     Pos = 0
  167.                 Else
  168.                     Pos += 1
  169.                 End If
  170.             End If
  171.         End Sub
  172.  
  173.         Public Function Count() As Integer
  174.             Return (Bits.Count * 8) + Pos
  175.         End Function
  176.  
  177.         Public Sub Clear()
  178.             Bits.Clear()
  179.             ByteValue = 0
  180.             Pos = 0
  181.         End Sub
  182.  
  183.         Public Function ToBytes() As Byte()
  184.             If Pos = 0 Then
  185.                 Return Bits.ToArray
  186.             Else
  187.                 Dim temp As New List(Of Byte)(Bits)
  188.                 temp.Add(ByteValue)
  189.                 Return temp.ToArray
  190.             End If
  191.         End Function
  192.  
  193.         Public Function ToArray() As BitArray
  194.             Dim newBytes() As Byte = Bits.ToArray
  195.             For i = 0 To newBytes.Length - 1
  196.                 newBytes(i) = ReverseByteBits(newBytes(i))
  197.             Next
  198.             Dim newBitArray As New BitArray(newBytes)
  199.             Erase newBytes
  200.             If Pos > 0 Then
  201.                 newBitArray.Length += Pos
  202.                 For i = Bits.Count * 8 To Count() - 1
  203.                     newBitArray(i) = Bit(i)
  204.                 Next
  205.             End If
  206.             Return newBitArray
  207.         End Function
  208.     End Class
  209. End Namespace
');