"converting hex to string in c?" Code Answer


0xaa overflows when plain char is signed, use unsigned char:

#include <stdio.h>

int main(void)
    unsigned char readingreg[4];
    readingreg[0] = 0x4a;
    readingreg[1] = 0xaa;
    readingreg[2] = 0xaa;
    readingreg[3] = 0xa0;
    char temp[4];

    sprintf(temp, "%x", readingreg[0]);
    printf("this is element 0: %sn", temp);
    return 0;
By ICanChange on May 18 2022

Answers related to “converting hex to string in c?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.