#include <iostream>
#include <string>
#include <iomanip>

unsigned char hex2dec(const std::string &s, size_t pos)
{
	char ch = s[pos];

	if (ch >= 'A' && ch <= 'F')
		return (ch - 'A') + 10;

	if (ch >= 'a' && ch <= 'f')
		return (ch - 'a') + 10;

	if (ch >= '0' && ch <= '9')
		return (ch - '0');

	// error!
	return 0;
}

unsigned char decodeHexByte(const std::string &s, size_t pos)
{
	return (hex2dec(s, pos) << 4) | hex2dec(s, pos+1);
}

int main()
{
	std::string keyInStr = "1314191A1B";
	unsigned char keyInHex[5] = {};

	for (int i = 0, j = 0; i < 5; ++i, j += 2)
	{
    	keyInHex[i] = decodeHexByte(keyInStr, j);
		std::cout << std::hex << std::setw(2) << std::setfill('0') << (int) keyInHex[i] << " ";
   	}

	return 0;
}