Boolean values to bytes

  • Thread starter Thread starter Jay Dee
  • Start date Start date
J

Jay Dee

I would like to no how to convert an array of 16 Boolean values into
an array of 2 bytes.

I can find plenty of examples to get Booleans from bytes but can not
get my head round how to do it in reverse.

Could someone explain or point me in the right direction.

Thanks a lot

Jay Dee
 
I would like to no how to convert an array of 16 Boolean values into
an array of 2 bytes.

I can find plenty of examples to get Booleans from bytes but can not
get my head round how to do it in reverse.

Do you mean that you want to pack 16 boolean values into 16 bits
(which would be 2 bytes)?

If so, then by far the easiest way to do it and avoid messing with
bitwise operators is to use BitArray:

bool[] input = new bool[16];
byte[] output = new byte[2];
....
new BitArray(input).CopyTo(output, 0);
 
Back
Top