How can I read individual bit values in a returned integer
-
-
I am calling an API function that returns an Integer. MSDN documentation states 'The only valid bits in the return value are those that correspond to the bits set in the mask parameter' How do I read these individual bit values. Regards, SAK:)
The API documentation probably has a list of values that can be ORed together to make the mask that you pass in as the mask parameter. To check if a bit is set, take the return value and AND it with the bit value you want. ie
int ret = APIFunc(MASK1 | MASK2);
if (ret & MASK1)
{
// MASK1 bit is set;
}
etc.--- The Center for Disease Control in Atlanta announced that Clinton has proven that you can get sex from Aides.
-
I am calling an API function that returns an Integer. MSDN documentation states 'The only valid bits in the return value are those that correspond to the bits set in the mask parameter' How do I read these individual bit values. Regards, SAK:)
An alternate solution that I have found useful when having to check a specific bit, like checking whether bit 29 in a 32 bit value is on or off, is using the std::bitset class. std::bitset<32> keyBits; if ( keyBits[29] == 1 ) { //bit 29 is set //do something }