I prefer a bit more of an elegant solution
Code:
union ByteBitfield
{
unsigned char Value;
struct
{
bool Zero : 1,
One : 1,
Two : 1,
Three : 1,
Four : 1,
Five : 1,
Six : 1,
Seven : 1;
} Bits;
};
Now you can access the bits and the value quickly and easily without the nasty shifting anding and oring that's in Salem's example!
Code:
ByteBitfield MyData;
MyData.Value; // Gets you the value of the number
MyData.Bits.Zero; // Gives you "true" if the Zero bit is set to 1
MyData.Bits.One; // Gives you "true" if the One bit is set to 1
if( MyData.Bits.Three )
{
/* Do Something */
}
// You can also change the bit extremely easily
MyData.Bits.Three = true; // Set's bit Three to 1
MyData.Bits.Four = !MyData.Bits.Four; // Toggles bit Four
See! No nasty shifting, compilments, anding oring, or even comparisons!
Sorry to disagree with you Salem!