While my power was out :p
I had alot of time to read, so here is a clean C++ way of testing bits.
:)Code:#include <iostream>
#include <bitset> // Include the bitset header
int main ( void )
{
// Set the container
// Since I'm testing a single byte you want the size to be 8
// You can change this to the bit size of the variable your testing
std::bitset<8> flags;
// Value to test
unsigned char value = 0x3D;
// Set the flags
flags |= value;
// Display the binary number
std::cout << flags << std::endl;
// The bits are stored in an array -----------
// You can test each one ---------------------
for ( int loop = 0; loop < 8; loop++ ) {
if ( flags[loop] )
std::cout << "Flag " << loop << " is set" << std::endl;
else std::cout << "Flag " << loop << " is not set" << std::endl;
}
// -------------------------------------------
// -------------------------------------------
return 0;
}