String Hex to Dec conversion. 
Author Message
 String Hex to Dec conversion.

Hello everybody,

I need to know if it is possible to convert a hexadecimal string to a decimal
string. I can't use the sscanf(<hex_string>, "%x", &<variable>) and the
sprintf(<dec_string>, "%d", <variable>) calls, because the hexadecimal string
is to big to fit in a C variable.

If someone did this already please let me know. The other direction (dec to hex)
is also welcome.

If you think it is NOT possible, tell me.

Thank you,
--

  ______                Van Landeghem Rudi      Switching Systems Devision se123
  \    /Alcatel                               F. Wellesplein 1, B-2018 Antwerpen




Mon, 01 Apr 1996 23:05:19 GMT  
 String Hex to Dec conversion.

Quote:
>I need to know if it is possible to convert a hexadecimal string to a decimal
>string. I can't use the sscanf(<hex_string>, "%x", &<variable>) and the
>sprintf(<dec_string>, "%d", <variable>) calls, because the hexadecimal string
>is to big to fit in a C variable.

Convert an int's worth at a time into an array of ints, then use a bignum
package to extract ints worth.

--
#include        <standard.disclaimer>
 _
Kevin D Quitt                   96.37% of all statistics are made up



Tue, 02 Apr 1996 00:07:28 GMT  
 String Hex to Dec conversion.

|
|Hello everybody,
|
|I need to know if it is possible to convert a hexadecimal string to a decimal
|string. I can't use the sscanf(<hex_string>, "%x", &<variable>) and the
|sprintf(<dec_string>, "%d", <variable>) calls, because the hexadecimal string
|is to big to fit in a C variable.
|
|If someone did this already please let me know. The other direction (dec to hex)
|is also welcome.
|
|If you think it is NOT possible, tell me.

Well, the laziest solution I can come up with (and I always come up with
lazy solutions ;-) is using `dc(1)' and a `popen(3)' call. Just write
the big hexadecimal string to a file, like:

FILE *f= fopen("tmpfile", "w");
fwrite(f, "10o16i%sp\n", big_hex_string);
fclose(f);

and `popen()' the following command:

FILE *f= popen("dc tmpfile", "r");
fgets(big_dec_string, ENOUGH, f);
pclose(f);

If all went ok (by checking all the return values), the string
`big_dec_string' should contain the decimal representation of
the hexadecimal representation contained in `big_hex_string'.
Iff (two `f's ;-) you're running some sort of OS that can spell
`Unix' of course ...

Oh, and don't forget to clean up the mess afterwards by doing a:

unlink("tmpfile");

kind regards,


---------------------------------------------------------------------------
`I love you, you love me' ... *bwork* I _hate_ that damned Barney thing.
        -- Kelly Scott (anti dino)



Tue, 02 Apr 1996 07:25:10 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help... conversion of hex to dec

2. Text to Hex to Dec conversion

3. dec to hex conversions.....more

4. BIN HEX DEC conversions...HELP!!!!

5. String conversion to Hex String

6. String conversion to Hex String

7. Hex string to void * conversion (was: Re: Language lawyer

8. conversion into hex of string

9. Hex to String conversion

10. hex string conversion

11. Help with a hex string conversion

12. String conversion and double-to-string conversion

 

 
Powered by phpBB® Forum Software