>In essence, how would you use a unsigned short as a bit >mask ?
A mask can be used to check if a certain bit, or bits, is set or not.
To check if bit 2 is set (note that bit 0 is the first bit), you need the following mask:
unsigned short mask = 0x04;
To check if bit 2 is set, you could do:
if (variable & mask)
{
/* the bit is set */
}
>What's the best way to print the bits and use/manipulate them?
Manipulation with bits can be done best with the bit-operators, look them up in your C book.
To print a byte in binary, you could do something like:
Code:
unsigned char value = 0x11; /* just a value */
unsigned char mask = 0x80;
unsigned char bits [8];
int i;
for (i = 0; i < 8; i++)
{
bits [i] = ((value & mask) != 0);
mask >>= 1; /* shift all bits one to right */
printf ("%d", bits [i]);
}