c - Getting a Character Representation of Hexadecimal Digit (Creating a char* to display a Hex Value) -
c - Getting a Character Representation of Hexadecimal Digit (Creating a char* to display a Hex Value) -
i've been looking half hr , can't seem find process setting char* points string of characters correspond hexidecimal string.
just clarify, i'm trying take hexidecimal string, (say 0x0043 example) , end character string contains "0x0043" can used on lcd display or written file easily.
i'm sure there easy way this, have found no leads. in know on this?
edit: embedded project, don't have access predefined functions.
convert 1 hex digit @ time.
void foo(unsigned x) { char buf[2 + sizeof x * 2 + 1]; char *p = &buf[sizeof buf - 1]; *p-- = '\0'; { *p-- = "0123456789abcdef"[x&15]; x >>= 4; } while (p != &buf[1]); *p-- = 'x'; *p = '0'; // utilize p }
c string hex ascii representation
Comments
Post a Comment