Question: I have an array with 16 elements. I would like to evaluate these to a boolean 0 or 1 and then store this in 2 bytes so i can write to a binary file. How do I do this?

Answer: 
You have to use [bitwise operators](http://msdn.microsoft.com/en-us/library/17zwb64t(VS.80).aspx). 

Here's an example:

```
int firstBit = 0x1;
int secondBit = 0x2;
int thirdBit = 0x4;
int fourthBit = 0x8;

int x = firstBit | fourthBit; /*both the 1st and 4th bit are set */
int isFirstBitSet = x & firstBit; /* Check if at least the first bit is set */

```
Something like this.

```
int values[16];
int bits = 0;
for (int ii = 0; ii < 16; ++ii)
{
    bits |= (!!values[ii]) << ii;
}

unsigned short output = (unsigned short)bits;

```

the expression (!!values[ii]) forces the value to be 0 or 1, if you know for sure that the values array already contains either a 0 or a 1 and nothing else, you can leave of the !!

You could also do this if you don't like the !! syntax. 

```
int values[16];
int bits = 0;
for (int ii = 0; ii < 16; ++ii)
{
    bits |= (values[ii] != 0) << ii;
}

unsigned short output = (unsigned short)bits;

```