Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Headaches with large base 11 numbers 1

Status
Not open for further replies.

Nosferatu

Programmer
Joined
Jun 9, 2000
Messages
412
Location
RO
Hey...

Can anybody give me some clues on how to deal efficiently with extremely large numbers?
I have to convert these huge base11 numbers (64 digits) to base36 numbers and my mind is starting to self-destruct.

Does anybody have some ideas in this area?
First of all, I don't know how to convert such a number to binary (from a character string) efficiently.
I can imagine writing addition algorithms in base11, but I don't think that what I'd do would be efficient for such numbers.

Any help is appreciated...
Thank you. [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
Interesting concept. Presumably the base 11 is 0-A and base 36 is 0-Z. If you are using a MS compiler, have a look at strtol. Here is a sample program

#include <stdio.h>
#include <stdlib.h>

main ()
{
char* base11[] = {&quot;A&quot;, &quot;10&quot;, &quot;100&quot;, &quot;123A&quot; };
char* last;
long val11, val16, val36;
int ii;

for (ii = 0; ii < sizeof(base11)/sizeof(base11[0]); ii++)
{
val11 = strtol (base11[ii], &last, 11);
val16 = strtol (base11[ii], &last, 16);
val36 = strtol (base11[ii], &last, 36);
printf (&quot;%s base 11 is %d base 10\n&quot;, base11[ii], val11);
printf (&quot;%s base 16 is %d base 10\n&quot;, base11[ii], val16);
printf (&quot;%s base 36 is %d base 10\n&quot;, base11[ii], val36);
}

return 0;
}
 
why not 'dc', no limits and works on char-strings,
try on you unix:
echo &quot;scale=99; (33/7)*(10^7)&quot;|/bin/bc
'bc' is a preprocessor to 'dc'
bc -c gives the 'dc' syntax.
i posted 'pipe to dc' in this forum -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Thanks Jamisar, I will try that, but I am working this on a NT/2000 platform. It would be interesting to see if there's a source code for the dc program.
But is the program working with extremely large numbers?
(xwb - the numbers to be processed are way above the ranges handled by any integer datatype on any computer I know - 64 digits!!!)
I tried to look at the gnu-gmp library but really freaked-out...

The solution I am aiming at is to make use of the fact that 36 = 6*6 so, if I will convert the number to base6, obtaining the radix 36 representation will be trivial - group 2 digits from base6 together to form 1 digit in base 36, the same idea that works for base2-base4,8,16...
[red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
You might want to search for some math libraries that have a &quot;HugeInt&quot; class or somesuch. I know people have written them, I've just never needed to use one so I don't know of any good ones. I'm sure there're also libraries out there to do the base conversion.

I'll check on those and let you know if I find anything.
 
Nosferatu, i found an old (still running) dc-src file
if interested send an email to priam@freenet.de
:) -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top