Support 0B... syntax for binary numbers.

This commit is contained in:
PKEuS 2012-09-11 08:39:01 +02:00
parent 95f4bb3e97
commit 77b5175ec3
2 changed files with 2 additions and 1 deletions

View File

@ -116,7 +116,7 @@ bool MathLib::isHex(const std::string& str)
bool MathLib::isBin(const std::string& str)
{
bool sign = str[0]=='-' || str[0]=='+';
return(str.compare(sign?1:0, 2, "0b") == 0 && str.find_first_not_of("10b", 1) == std::string::npos);
return((str.compare(sign?1:0, 2, "0b") == 0 || str.compare(sign?1:0, 2, "0B") == 0) && str.find_first_not_of("10bB", 1) == std::string::npos);
}
bool MathLib::isInt(const std::string & s)

View File

@ -171,6 +171,7 @@ private:
ASSERT_EQUALS(-1 , MathLib::toLongNumber("-0b1"));
ASSERT_EQUALS(215 , MathLib::toLongNumber("0b11010111"));
ASSERT_EQUALS(-215 , MathLib::toLongNumber("-0b11010111"));
ASSERT_EQUALS(215 , MathLib::toLongNumber("0B11010111"));
// from base 10
ASSERT_EQUALS(10 , MathLib::toLongNumber("10"));