uint16_t exArray[] = "3030422320303030373830434441453141542355";
I don't think this does what you are trying to do. The string literal is treated as a pointer to a const char. It's not even compiling for me. What you want here is something like this:
const char * exArray = "3030422320303030373830434441453141542355";
It's 20 pairs of hex values that each represent an ASCII character
(eg. 0x41 = A). How can I split them up to calculate a checksum?
You could loop through the array, doing what you want to do with the two chars inside the loop:
for (int i = 0; exArray[i]; i+=2) {
printf("my chars are %c and %c\n", exArray[i], exArray[i+1]);
// do the calculations you need here using exArray[i] and exArray[i+1]
}
Alternatively, how can I merge two values in an array to be one value?
(eg. '4', '1' -> '41')
I'm not sure what you mean here. Do you mean "41"
, as in the string representing 41? To do that, allocate three chars, then copy over those two chars and a null terminator. Something like
char hexByte[3];
hexByte[2] = 0; // setting the null terminator
for (int i = 0; exArray[i]; i+=2) {
hexByte[0] = exArray[i];
hexByte[1] = exArray[i+1];
printf("the string \"hexByte\" is: %s\n", hexByte);
// do something with hexByte here
}
If you want to convert it to its integer representation, use strtol
:
printf("int value: %ld\n", strtol(hexByte, 0, 16));