24 lines
355 B
C++
24 lines
355 B
C++
#include "hexadecimal.h"
|
|
|
|
namespace hexadecimal {
|
|
|
|
int convert(const std::string &input)
|
|
{
|
|
int result = 0;
|
|
|
|
for (auto ch : input) {
|
|
|
|
ch = tolower(ch);
|
|
|
|
if (!isxdigit(ch))
|
|
return 0;
|
|
|
|
result *= 16;
|
|
result += ch <= '9' ? ch - '0'
|
|
: ch - 'a' + 10;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
}
|