#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <iostream>
#include <string>
#include <sstream>
#include <cctype>
#include <algorithm>
using namespace std;
int convert(char ch) {
if (isdigit(ch)) {
return ch - '0';
}
if (isupper(ch)) {
return ch - 'A' + 10;
}
if (islower(ch)) {
return ch - 'a' + 10;
}
return -1;
}
long hex_str_to_dec_num(const char *hex_str) {
long sum = 0;
long t = 1;
int len = strlen(hex_str);
for (int i = len - 1;i >= 0;i--) {
sum += t * convert(hex_str[i]);
t = t << 4;
}
return sum;
}
long hex_str_to_dec_num1(const char *hex_str) {
long value = 0;
istringstream ss(hex_str);
ss >> std::hex >> value;
return value;
}
int main() {
for (int i = 0;i < 1000000;i++) {
// hex_str_to_dec_num("A1BCA1"); // 0.108s
hex_str_to_dec_num1("A1BCA1"); // 0.965s
}
return 0;
}