Convert Hex to ASCII

I have a Hex string like this:

74 65 73 74

And I want to translate it back to its original string, "test"...

Could someone post some example code for this conversion...

Thanks!!!

-- -Sam

char str[5];

str[0] = 74;
str[1] = 65;
str[2] = 73;
str[3] = 74;
str[4] = 0;

Or, if you have hex in a string like “74”, you would convert it like:

hex = “74”;

char hexNibbleToChar(char nibble)
{
if (nibble >= ‘0’ && nibble <= ‘9’)
return nibble - ‘0’;
else if (nibble >= ‘a’ && nibble <= ‘f’)
return 10 + nibble - ‘a’;
else
return 10 + nibble - ‘A’;
}

str[0] = hexNibbleToChar(hex[0]) * 16 + hexNibbleToChar(hex[1]);

  • Ben