Convert byte to bit array

Hi all,
i have a vallue in byte and would like to convert it into bit array

byte b = 3;
char[] b = ConvertToBit(b)

now b will have
b = 00000011

any ideas how to do this in C# ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shay050799Author Commented:
don't work for me..any other ideas ?
Bob LearnedCommented:
byte b = 5;
System.Collections.Specialized.BitVector32 bv = new System.Collections.Specialized.BitVector32(b);


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

BitArray bits = new BitArray (new byte[] {b});

Now you can check/set the bits using:

bits[0] = 1;
byte b0 = bits[0];

P.S. You need using System.Collections in the beginning of your file.
Bob LearnedCommented:
I favor the BitVector32 over the BitArray for its efficiency.  If I need more than 32 bits, then I use the BitArray class.

BitArray ba = new BitArray(8);
ba[3] = true;
byte[] bar = new byte[ba.Length / 8];
ba.CopyTo(bar, 0); // bit array to byte array
BitArray backtobitarray = new BitArray(bar); // byte array to bit array
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.