Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: Converting ascii hex values to hex bytes Message-ID: <4005@goanna.cs.rmit.oz.au> Date: 18 Oct 90 05:32:19 GMT References: <298@cti1.UUCP> <1990Oct17.162529.20096@Neon.Stanford.EDU> Distribution: comp Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 17 In article <298@cti1.UUCP> mpledger@cti1.UUCP (Mark Pledger) writes: >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 void convert_internet_address_to_binary(const char *inet_addr, char *bin) { int i[4]; sscanf(inet_addr, "%d.%d.%d.%d", &i[0], &i[1], &i[2], &i[3]); bin[0] = i[0], bin[1] = i[1], bin[2] = i[2], bin[3] = i[3]; } Alas, the *scanf() family supports int*, short*, and long* arguments, but not char*, which is why we need i[]. -- Fear most of all to be in error. -- Kierkegaard, quoting Socrates.