Summary: Converting ascii hex to pure hex values
Doug Gwyn
gwyn at smoke.brl.mil
Wed Nov 7 20:19:09 AEST 1990
In article <302 at cti1.UUCP> mpledger at cti1.UUCP (Mark Pledger) writes:
>If you have a character string with the ascii representation of hex values
>(e.g. s[] = "63", which will be stored as TWO hex byte values \x9 & \x9.
No, the two successive values will be 0x36 and 0x33.
>I only want to store them as ONE hex byte of \x63. ... I am interested in
>creating (or finding) a routine that will take a character string as the
>argument, and returning the hex result in the same character string.
This is a trivial exercise. WARNING: String literals (as opposed to
arrays of char) are not necessarily modifiable.
void func( char *s ) {
register int i = s[0] - '0' << 4 | s[1] - '0';
s[0] = i;
s[1] = '\0';
}
This could be easily be made into a macro.
More information about the Comp.lang.c
mailing list