Path: utzoo!attcan!uunet!unhd!jwm775 From: jwm775@uunet!unhd (Jonathan W Miner) Newsgroups: comp.lang.c Subject: Re: Summary: Converting ascii hex to pure hex values Message-ID: <1990Nov5.000208.3226@uunet!unhd> Date: 5 Nov 90 00:02:08 GMT References: <302@cti1.UUCP> Reply-To: jwm775@unhd.UUCP (Jonathan W Miner) Distribution: comp Organization: Computing Information Services, University of New Hampshire Lines: 26 In article <302@cti1.UUCP> mpledger@cti1.UUCP (Mark Pledger) writes: > [... DELETED STUFF ...] >currently use atoi() and just write out the int to disk. 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. Try this: void convert(s) char s[3]; { int value; value = ((s[0] - '0') * 100) + ((s[1] - '0') * 10) + (s[2] - '0'); s[0] = value / 256; s[1] = value % 256; s[2] = 0; } This assumes that the input will always be in the range '000' to '999'. -- ----------------------------------------------------------------- Jonathan Miner | I don't speak for UNH, and UNH does not jwm775@unhd.unh.edu | speak for me! (603)868-3416 | Rather be downhill skiing... or hacking...