Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. bool[] from value

bool[] from value

Scheduled Pinned Locked Moved C#
csharpcomdata-structurestools
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DaveyM69
    wrote on last edited by
    #1

    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)

    M J 2 Replies Last reply
    0
    • D DaveyM69

      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)

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      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.

      D 1 Reply Last reply
      0
      • D DaveyM69

        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)

        J Offline
        J Offline
        JoeSharp
        wrote on last edited by
        #3

        hi had a look in the BitArray class in the System.Collections namespace. maybe this will help you. regards

        D 1 Reply Last reply
        0
        • M musefan

          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.

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          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)

          1 Reply Last reply
          0
          • J JoeSharp

            hi had a look in the BitArray class in the System.Collections namespace. maybe this will help you. regards

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            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)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups