I would like to pack bool array with max length 8 in one byte, send it over network and then unpack it back to bool array. Tried some solutions here already but it didn't work. I'm using Mono.
I made BitArray and then tried to convert it in byte
public static byte[] BitArrayToByteArray(BitArray bits)
{
byte[] ret = new byte[Math.Max(1, bits.Length / 8)];
bits.CopyTo(ret, 0);
return ret;
}
but I'm getting errors telling only int and long type can be used. Tried int instead of byte but same problem. I would like to avoid BitArray and use simple conversion from bool array to byte if possible