Converting ascii hex values to hex bytes
Mark Pledger
mpledger at cti1.UUCP
Wed Oct 17 21:08:26 AEST 1990
I have a little stumper of a question. I am writing software that accesses
a configuration file that stores IP addresses. The IP addresses are stored
as raw hex bytes. For example, an IP address of say 122.10.10.44 is stored
in the configuration file as 4 bytes 7A-0A-0A-2C. Now I am using fread()
and fwrite() to get a lot of different configuration data. What I want to
do is to be able to convert 122.10.10.44 into a character string of 4 bytes
that equals "\x7a\x0a\x0a\x2c". How can I convert the ascii representation
into hex? I tried using itoa(), but the result is in ascii character format
so if you used itoa(44,result,16), result[] = "2C". When written to disk,
the result[] string is actually written to disk as an ascii 2 (32h) and an
ascii C (43h). What I want is one byte equalling "\x2c".
Can anybody give me a hand? Thanks in advance.
--
Sincerely,
Mark Pledger
--------------------------------------------------------------------------
CTI | (703) 685-5434 [voice]
2121 Crystal Drive | (703) 685-7022 [fax]
Suite 103 |
Arlington, DC 22202 | mpledger at cti.com
--------------------------------------------------------------------------
More information about the Comp.lang.c
mailing list