I have an array of 128 booleans that represent bits. How can I convert these 128 bit representations into 16 bytes?
Example:
I have an array that looks like
The code is treating the first bit as the low bit of the word, so you end up with each word reversed. As a quick-and-dirty fix, try this:
bytes[byteIndex] |= (byte)(1 << (7-bitIndex));
That puts the first bit in the array at the highest position in the first byte, etc.