#include #include //From http://www.richelbilderbeek.nl/CppHexStrIsInt.htm //This solution was inspired by AsmGuru62 //http://www.programmersheaven.com/c/authorpage.asp?AuthorID=12069 //Checks if a C-style string only contains hexadecimal characters bool IsAllHex (const char* const must_be_hex) { char copy_of_param[64]; return( std::strtok ( std::strcpy(copy_of_param, must_be_hex), "0123456789ABCDEFabcdef") == 0); } int main() { assert(IsAllHex("0")==true); assert(IsAllHex("9")==true); assert(IsAllHex("A")==true); assert(IsAllHex("F")==true); assert(IsAllHex("-F")==false); //Does not accept negatives assert(IsAllHex("-F85AE")==false); //Does not accept negatives assert(IsAllHex("FFFFFFFFFFFFFFFFFFFFFFFFFFF")==true); assert(IsAllHex("G")==false); } //As option #1 also has defects in detecting negatives, you might want to change //the IsAllHex to the one below: //From http://www.richelbilderbeek.nl/CppHexStrIsInt.htm //This solution was inspired by AsmGuru62 //http://www.programmersheaven.com/c/authorpage.asp?AuthorID=12069 //Checks if a C-style string only contains hexadecimal characters //and minuses bool IsAllHex (const char* const must_be_hex) { char copy_of_param[64]; return( std::strtok ( std::strcpy(copy_of_param, must_be_hex), "0123456789ABCDEFabcdef-") == 0); }