I am working on a C# application. I have a byte variable, i want to iterate over all bits of it.
byte var = 3;
System.Collections.BitArray bits = new System.Collections.BitArray(var);
Console.WriteLine("Length of collection : " + bits.Length);
for (int i = 0; i < bits.Length; i++)
{
Console.WriteLine(bits[i]);
}
This code gives me the following output:
Length of collection : 3
False
False
False
But as the binary representation of 3 is 00000011 so i expect the following output
False
False
False
False
False
False
True
True
What am i doing wrong ? How can i achieve the required output
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…