TizzyT

IntegerToBooleanArray -TizzyT

Feb 14th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.90 KB | None | 0 0
  1.     Public Function IntegerToBooleanArray(ByVal Value As Integer) As Boolean()
  2.         If Value = 0 Then Return {False}
  3.         Dim bools() As Boolean = {}, pow As Integer = 0, index As Integer = 1
  4.         While True
  5.             If 2 ^ pow > Value Then
  6.                 pow -= 1
  7.                 ReDim bools(pow)
  8.                 bools(0) = True
  9.                 Value -= 2 ^ pow
  10.                 pow -= 1
  11.                 For i = pow To 0 Step -1
  12.                     If 2 ^ pow > Value Then
  13.                         bools(index) = False
  14.                     Else
  15.                         bools(index) = True
  16.                         Value -= 2 ^ pow
  17.                     End If
  18.                     index += 1
  19.                     pow -= 1
  20.                 Next
  21.                 Return bools
  22.             Else
  23.                 pow += 1
  24.             End If
  25.         End While
  26.         Return {}
  27.     End Function
Advertisement
Add Comment
Please, Sign In to add comment