Converting a binary string to hex
I have a string in binary and I need to convert it to hex. (Obvious right?)
What I'm trying to do is this:
Code:
for (z = 0; z < 20; z++)
sprintf(string, "%02x", out[z]);
Both out and string are defined as unsigned char[20]
Now, I know that hex characters take two bytes, so I also tried
Code:
for (z = 0; z < 20; z++)
y += sprintf(string+y, "%02x", out[z]);
Where y is initialized to 0. I keep getting damage after normal block errors. I thought it was becuase I was overwriting memory so I increased the size of string to 200, which should be MORE than enough room, but I get the same error. Any suggestions?