Summary: Converting ascii hex to pure hex values

Jonathan W Miner jwm775 at uunet!unhd
Mon Nov 5 11:02:08 AEST 1990


In article <302 at cti1.UUCP> mpledger at 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 at unhd.unh.edu   | speak for me! 
(603)868-3416         | Rather be downhill skiing... or hacking... 



More information about the Comp.lang.c mailing list