Question: I wondered how can I take an 8 bit variable,
and break it apart to 8 booleans, for a 'for' loop.
For example:

```
void byteWrite(byte byteIn)
{
  for(int i=0; i<8; i++)
  {
    PORTA |= 128; // STHP ON
    if(?)
      PORTB |= 4; //STCP ON
    else
      PORTB &=11;// STCP OFF
    _delay_ms(1);
    PORTA &= 63; // STHP OFF
    _delay_ms(1);
  }
  PORTB |= 2; // DS ON
  _delay_ms(1);
  PORTB &= 1; // DS OFF
}

```

Thanks.

Answer: 
Use bitwise-and, with shifts:

```
if((byteIn & (1 << i)) != 0)

```

This simply computes the bitmask `(1 << i)` for each step in the loop, and uses bitwise-and (the `&` operator) to check if the corresponding bit in `byteIn` is set.

This is a very common thing to do.

If you're worried about re-computing the mask on every iteration, you can use the constant mask `1` (i.e. check only the rightmost bit) and instead shift `byteIn` on each iteration:

```
if((byteIn & 1) != 0)
 ...
else
 ...
byteIn >>= 1;

```

The final line shifts `byteIn` one bit to the right, so that on the next iteration the and checks the next bit. This *can* be faster, since it is somewhat simpler in machine code (particularly for smaller processors, this looks like PIC code).

Note that both solutions above iterate from the least-significant (right-most) bit first, if that's not appropriate you need to reverse it of course.
```
for(uint8_t mask = 1<<7; mask!=0; mask>>=1)
{
  if(data & mask)
  {
    PORT |= mask;
  } 
  else
  {
    PORT &= ~mask;
  }
}

```