#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
#include <iterator>
#include <iomanip>

inline int char2hex(char c)
{
   if (c >= '0' && c <= '9') return c - '0';
   if (c >= 'a' && c <= 'f') return c - 'a' + 10;
   if (c >= 'A' && c <= 'F') return c - 'A' + 10;

}
std::vector<unsigned char> str2hex(const std::string& hexStr)
{
     std::vector<unsigned char> retVal;
     bool highPart = ((hexStr.length() % 2) == 0);  
     if (!highPart)
         retVal.push_back(0);
     std::for_each(hexStr.begin(), hexStr.end(), 
        [&](char nextChar) {
           if (highPart)
		retVal.push_back(0x10 * char2hex(nextChar));
           else
		retVal.back() += char2hex(nextChar);
           highPart = !highPart;
       }
     );

    return retVal;
}

int main() {
  std::string someHex =  "c45a1bf";
  std::vector<unsigned char> someUHex = str2hex(someHex);
  std::copy(someUHex.begin(), someUHex.end(), std::ostream_iterator<int>(std::cout << std::hex, ""));
}