I am trying to convert an array of chars into an array of hexadecimal numbers. Each char in the input array will be converted to two chars that represent the corresponding hexadecimal number.
This is my input:
char input[3] = "over";
This would be the output:
char output[6] = "6f766572";
How can I achieve this conversion in C without libraries? Thanks in advance.
My code is currently as follows:
void convert(char *input, int inputsize) {
char c;
char output[inputsize * 2];
for (int i = 0; i < inputsize; i++) {
c = input[i]
// change c to hex here
// put each letter of the hex into output[i * 2] and output[i * 2 + 1]
}
}
"6f766572"
takes 9 chars, 8 for the characters and 1 for the string terminator. – Jabberwocky Sep 17 '20 at 13:20