I need to invert this function which it’s used to covert strings representing hex values to char representation
char * extochar(char * in, int inLen){
int i,k;
int resInt[inLen/2];
char * resChar=malloc(inLen/2);
k=0;
for(i=0; i<inLen/2; i=i++){
resInt[k]=chartoint(in[i*2])<<4;
resInt[k]+=chartoint(in[(i*2)+1]);
k++;
}
for(k=0; k<inLen/2;k++){
resChar[k]=(char)resInt[k];
}
return resChar;
}
Note: Valid input are only strings consisting of 1234567890abcdef, and their length. I’m able to invert the second for cicle (quite easy) but not the first one!
Get a char pointer to your memory that you want to represent in hex form. Allocate a char[] buffer for the string result.
Call sprintf with the formatting:
You can use some basic pointer arithmetic to cycle through stringbufferptr/chartotranslateptr in order to do multiple chars at a time if you’re converting a uint64_t or something too.