Re: converting hex strings to decimal digits strings

New Message Reply About this list Date view Thread view Subject view Author view

Martin G. Diehl (mdiehl@nac.net)
Tue, 24 Mar 1998 12:28:40 -0500


Hamdi Tounsi wrote:
>
> sorry if this is trivial ...
> how to convert a byte string (a big integer) like 0x59, 0x42, 0x10
> (MSB) to a digits string like 5849616 suitable for ascii display
> 0x59*256^2 + 0x42*256 +0x10 = 5849616
> the bignum libs i'm using doesn't have that :(
>
> best regards

A simple algorithm (in Pseudo Pascal) would be:

        if NumberToConvert < 0 then
                result := '-0'
        else
                result := '0'; {result is a string}
                                        {digit is a character}
        while NumberToConvert <> 0 do
                begin
                        digit := NumberToConvert mod 10;
                        result := result + digit;
                        NumberToConvert := NumberToConvert div 10;
                end;

Havn't tested this code; quite sure this will work; learned it from
an algebra book that I read in '57 or '58.

Cheers

-- 
Martin G. Diehl

I am what I am. All opinions expressed within are strictly my own.

If Ziggy says "Time is what keeps everything from happening at once", and Newton teaches that Gravity brings all matter together, could we say that Time and Gravity have an antagonistic relationship?


New Message Reply About this list Date view Thread view Subject view Author view

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

The following archive was created by hippie-mail 7.98617-22 on Fri Aug 21 1998 - 17:16:12 ADT