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