Question: Can anyone suggest means of converting a byte array to ASCII in C? Or converting byte array to hex and then to ASCII?

[04/02][Edited]: To rephrase it, I wish to convert bytes to hex and store the converted hex values in a data structure. How should go about it?

Regards,
darkie

Answer: 
First of all you should take some more care on the formulation of your questions. It is hard to say what you really want to hear. I think you have some binary blob and want it in a human readable form, e.g. to dump it on the screen for debugging. (I know I'm probably misinterpreting you here).

You can use `snprintf(buf, sizeof(buf), "%.2x", byte_array[i])` for example to convert a single byte in to the hexadecimal ASCII representation. Here is a function to dump a whole memory region on the screen:

```

void
hexdump(const void *data, int size)
{
    const unsigned char *byte = data;

    while (size > 0)
    {
        size--;
        printf("%.2x ", *byte);
        byte++;
    }
}

```
Char.s and Int.s are stored in binary in C. And can generally be used in place of each other when working in the ASCII range.

```
int i = 0x61;
char x = i;

fprintf( stdout, "%c", x );

```

that should print 'a' to the screen.