Seems elementary but I am not sure how to get each bit from a byte. Thanks for the help
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As RyuuGan already posted you should go with the BitArrary. You just put the data in it by calling the constructor with the wanted elements.
Afterwards the instance has some interesting properties to easily access each bit. At first you can just call the index operator to get or set the state of each bit:
Also you can enumerate over all bits by just using a foreach loop (or any LINQ-stuff you like)
To get back from the bits to some specific type (e.g. int) is a little bit trickier, but is quite easy using this extension methods:
With this in place you can just get out of it with this single line of code: