If I understand the question correctly (there are no guarantees), you have a text string representing a number in decimal format ("1234"), and you want to convert it to a string in hexadecimal format ("4d2").
Assuming that's right, it would be best to convert the input string to an integer using sscanf() or strtol() , and then use sprintf() using the %x conversion specifier to write the hexadecimal version to another string
char text[] = "1234"; char result[SIZE]; // where SIZE is big enough to hold any converted value int val; val = (int) strtol(text, NULL, 0); // error checking omitted for brevity sprintf(result, "%x", val);
source share