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. Converting ulong into an array of booleans

Converting ulong into an array of booleans

Scheduled Pinned Locked Moved C#
data-structureshelptutorialquestion
2 Posts 2 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.
  • N Offline
    N Offline
    NiteShade
    wrote on last edited by
    #1

    Hello, I have been trying to convert a ulong into it's component bits. Unfortunately there is no converstion operation, and using pointers this is not possible, since there is no pointer of size 1 bit. I have also tried the BitArray operation, but this only allows for int32 size variables... so I converted my ulong into 2 ints. However the result was not correct. Now I do not have any ideas how to proceed. Could somebody pls help me?

    M 1 Reply Last reply
    0
    • N NiteShade

      Hello, I have been trying to convert a ulong into it's component bits. Unfortunately there is no converstion operation, and using pointers this is not possible, since there is no pointer of size 1 bit. I have also tried the BitArray operation, but this only allows for int32 size variables... so I converted my ulong into 2 ints. However the result was not correct. Now I do not have any ideas how to proceed. Could somebody pls help me?

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      A combination of masking and shifting will work. For example:

      ulong ulValue = 0xF345612347892019UL;
      ulong ulMask;
      int iBitValue;

      for ( int iBit = 0; iBit < 64; ++iBit )
      {
      ulMask = 1UL << iBit;
      iBitValue = (int)((ulValue & ulMask) >> iBit);

      System.Console.WriteLine( "Bit {0}: {1}", iBit, iBitValue );
      }

      Stability. What an interesting concept. -- Chris Maunder

      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