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: 
This solution avoid the use of the if inside the loop:

```
unsigned short binary = 0, i;
for ( i = 0; i < 16; ++i )
  binary |= (array[i] != 0) << i;

```
Declare an array `result` with two bytes, then you loop through the source array:

```
for (int i = 0; i < 16; i++) {
  // calclurate index in result array
  int index = i >> 3;
  // shift value in result
  result[index] <<= 1;
  // check array value
  if (theArray[i]) {
    // true, so set lowest bit in result byte
    result[index]++;
  }
}

```