The easiest way to solve this problem would be with a simple lookup table. Define a table of strings and hex-numbers like:
Code:
typedef struct
{
char *string;
int hexvalue;
} string_hex_s;
string_hex_s string_hex_table [..] =
{
{"30", 0x30},
{"31", 0x31},
{"32", 0x32},
{"33", 0x33},
{"34", 0x34}
....
};
Each time read two chars of the original string into a string, search for the string in the table and you find the hex-value immediately.
Another method, comparable to your method. Read two characters at once. Then use atoi to convert the string to integer and finally convert to hex-value.
Converting from decimal to hex can be done like the following example, the way you calculate it is not correct:
445 / 16 = 27 R 13
27 / 16 = 1 R 11
1 / 16 = 0 R 1
1= 1, 11 = B and 13 = D, so 445 = 1BD