How can i iterate bits in a byte array?
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.
You’d have to write your own implementation of
Iterable<Boolean>which took an array of bytes, and then createdIterator<Boolean>values which remembered the current index into the byte array and the current index within the current byte. Then a utility method like this would come in handy:(where
bitranges from 0 to 7). Each timenext()was called you’d have to increment your bit index within the current byte, and increment the byte index within byte array if you reached “the 9th bit”.It’s not really hard – but a bit of a pain. Let me know if you’d like a sample implementation…