Re: print as a base 10 number



mike7411@xxxxxxxxx said:

If you have a string of a few hundred ones and zeros that represents a
binary number, what is the best way to print this as a base 10 number?

Best way? No idea. But if I tell you *a* way, then you can compare it
against other ways you may know about.

1) Create a "bignum" from the binary string. Call this N.
2) Define an empty string, S.
3) Deal with the trivial case where N is 0: S = "0" and stop.
4) while(N > 0)
5) D = N modulo 10
6) Add the string equivalent of D to the end of S
7) N becomes N / 10 (ignoring remainder)
8) endwhile
9) reverse S and stop.

GNU does a bignum library called GMP. Miracl is an obvious alternative (no
final 'e' on Miracl).

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.



Relevant Pages