Re: print as a base 10 number
- From: Richard Heathfield <invalid@xxxxxxxxxxxxxxx>
- Date: Tue, 26 Sep 2006 15:40:19 +0000
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)
.
- Follow-Ups:
- Re: print as a base 10 number
- From: CBFalconer
- Re: print as a base 10 number
- References:
- print as a base 10 number
- From: mike7411
- print as a base 10 number
- Prev by Date: Re: "It doesn't matter if you're a good programmer, it's the syntax that matters"
- Next by Date: Re: the lowest number of comparisons in string matching
- Previous by thread: print as a base 10 number
- Next by thread: Re: print as a base 10 number
- Index(es):
Relevant Pages
|
|