hexadecimal: iteration 1

This commit is contained in:
Dmitry Kokorin 2016-04-08 00:14:06 +03:00
parent 9c9d3a5380
commit cb28e44c67
5 changed files with 192 additions and 0 deletions

View file

@ -0,0 +1,24 @@
#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;
}
}