Following on this question How to convert a string to hex and vice versa in c??
I run the following code:
#include <stdio.h>
int main (int argc, char *argv[])
{
char str[] = { 0x58, 0x01, 0x02, 0x20, 0x22, 0x00, 0xC5};
char hex[32] = {0}, hex2[32] = {0};
for (int i = 0; i < sizeof(str); i++) {
sprintf(hex + i*2, "%02X", str[i]);
}
for (int i = 0; i < sizeof(str); i++) {
sprintf(hex2 + i*2, "%02X", str[i] & 0xff);
}
printf("hex = %s\nhex2 = %s\n", hex, hex2);
return 0;
}
I get this result:
hex = 580102202200FFFFFFC5
hex2 = 580102202200C5
I wonder why there is more FFFFFF
without 0xFF?