is convert unsigned char / int to hex, trouble is no correct translate ascci table: original: 0D, converted: AD code:
char int_to_hex(int d) {
if (d < 0) return -1;
if (d > 16) return -1;
if (d <= 9) return '0' + d;
d -= 10;
return (char)('A' + d);
}
void uint_to_hex(unsigned char in, char **out, int *olen) {
int i = 0;
int remain[2];
int result = (int)in;
while (result) {
remain[i++] = result % 16;
result /= (int)16;
}
for (i = 1; i >= 0; --i) {
char c = int_to_hex(remain[i]);
if( (int)c == -1 ) { continue; }
*((*out) + (*olen)) = (char)c; (*olen)++;
}
}
where is incorrect ?..