Path: utzoo!attcan!uunet!cti1!mpledger From: mpledger@cti1.UUCP (Mark Pledger) Newsgroups: comp.lang.c Subject: Converting ascii hex values to hex bytes Message-ID: <298@cti1.UUCP> Date: 17 Oct 90 11:08:26 GMT Distribution: comp Organization: Comprehensive Technologies Int., Arlington VA Lines: 34 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@cti.com --------------------------------------------------------------------------