Eric Young (eay@cryptsoft.com)
Wed, 25 Mar 1998 09:21:21 +1000 (EST)
On Tue, 24 Mar 1998, Martin G. Diehl wrote:
> > 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 :(
> digit := NumberToConvert mod 10;
> result := result + digit;
> NumberToConvert := NumberToConvert div 10;
One simple improvment it not to use '10' but use the largest size power of 10
that will fit in the word size of the machine. For a 32 bit machine,
1000000000L can be used. To save the mod, just keep on divinding the number
by 1000000000L, saving the result, then when you have 0 left, print out the
numbers (in reversed order :-). You will probably have to do a little playing
around to drop the leading 0's on the first number printed.
eric
The following archive was created by hippie-mail 7.98617-22 on Fri Aug 21 1998 - 17:16:13 ADT