Not sure it has to be that confusing, I was able to run your code with the following minor corrections:
You don't use anything on the first line anyway, and the only other thing is that the hexstr_ptr has to point to an UPPERCASE hex value.
//int nxt_char, cmdopt, cmdport, nibble0, nibble1;//, index;
const char hex_str = "0123456789ABCDEF";
int hex_value = 0;
I printed my output like this:
foo is your function.
std::cout<< std::hex << foo("DEADBEEF") << std::endl;