bool[] from value
-
Is there any built in method that create a boolean array from a byte or int - basically a bit array indicating whether each element (bit) is set or not? I've easily created my own function to do this but wondered if there was already an in built method? [Edit] Jst found the BitArray class that will take a byte[] parameter and set the bits accordingly :doh: [/Edit]
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
Is there any built in method that create a boolean array from a byte or int - basically a bit array indicating whether each element (bit) is set or not? I've easily created my own function to do this but wondered if there was already an in built method? [Edit] Jst found the BitArray class that will take a byte[] parameter and set the bits accordingly :doh: [/Edit]
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)I dont think there is the way you describe. But depending on your needs for it you could use an enum with the 'Flags' attribute. This can be set as a whole be passing it a byte or int... [Flags] public enum MyFlags{ Flag1, Flag2, Flag3, Flag4 } public MyFlags myFlags = 4;//set with int or byte value this will result in Flag3 being set and the others not set... likewise, assigning a value of '6' would set both Flag2 and Flag3.
Life goes very fast. Tomorrow, today is already yesterday.
-
Is there any built in method that create a boolean array from a byte or int - basically a bit array indicating whether each element (bit) is set or not? I've easily created my own function to do this but wondered if there was already an in built method? [Edit] Jst found the BitArray class that will take a byte[] parameter and set the bits accordingly :doh: [/Edit]
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
I dont think there is the way you describe. But depending on your needs for it you could use an enum with the 'Flags' attribute. This can be set as a whole be passing it a byte or int... [Flags] public enum MyFlags{ Flag1, Flag2, Flag3, Flag4 } public MyFlags myFlags = 4;//set with int or byte value this will result in Flag3 being set and the others not set... likewise, assigning a value of '6' would set both Flag2 and Flag3.
Life goes very fast. Tomorrow, today is already yesterday.
The BitArray class did it. It's actually a UInt16 (from an interop function) that I needed to convert.
_ChannelMask
is the UInt16 and_ChannelAvailability
is the Boolean[]new BitArray(new byte[] { (byte)_ChannelMask, (byte)(_ChannelMask >> 8) })
.CopyTo(_ChannelAvailability, 0);Thanks for the suggestion :-D
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
hi had a look in the BitArray class in the System.Collections namespace. maybe this will help you. regards
Thanks - I actually discovered that class just after posting! Serves me right for not googling for BitArray!
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)