c++ bitwise AND, expressing number literal
lets say I have a string of characters, (I am sure they are all letters)
I want to make an is_uppercase function, thus my goal in this exercise is to check if the 5 bit is a 0 or not... (adding 32 to any uppercase gives me a lowercase)
Code:
bool is_uppercase(std::string word)
{
BOOST_FOREACH(char c, word)
{
if(c & 32)
{
return false;
}
}
return true;
}
The above code seems to work, though in this case I do not have to do any operations on the number.
but If i needed to use the ~ operator on the number 32 it would have messed me up by making the number negative...
Code:
if ( ~c | ~32)
// yields incorrect result
ive tried but it also leads me to -33 .. (which is wrong)
how would I express a number as 'unsigned' ?