Simple question: considering that a bool (true, false) is the same as a bit (1, 0), what is the correct way to convert eight bools into a byte in C#?
Examples:
true, true, true, true, true, true, true, true == 11111111 == 255
true, false, false, false, false, false, false, false == 10000000 == 128
false, false, false, false, false, false, false, false == 00000000 == 0
The above is the first part. I want to create an extension method, like that:
public static byte[] ToByteArray(this bool[] bitArray)
{
// stuff here
return byteArray;
}
The result must be a byteArray that contains eight times less elements than the bool array.