base conversion of large numbers
Author Message base conversion of large numbers

Hi !

I know how to convert between different bases , but I would like
to convert from decimal to binary and I want to convert a Number that is
only limited by memory not by 'longint'

I know there is 'some' way to do this with an array , but I am not that
experienced yet

If you could help me with source code , this would be great , because I
have not much idea about implementing it in Pascal , or maybe there is
an URL . ?

please help

thank you

Mike

Wed, 18 Jun 1902 08:00:00 GMT  base conversion of large numbers

Quote:

> Hi !

> I know how to convert between different bases , but I would like
> to convert from decimal to binary and I want to convert a Number that
> is
> only limited by memory not by 'longint'

> I know there is 'some' way to do this with an array , but I am not
> that
> experienced yet

Converting to binary is pretty simple.  The first thing to decide
is how you want to
represent the binary number.  I'll assume you are going to represent it
by a string of '0'
and '1' characters.

If the number is 0 (in decimal), then it is '0' (in binary).  If it
is odd, its LSC (least significant character) is '1', otherwise it is
'0'.  Finally, if you can divide the number by 2 (throwing away the
remainder), then
binarystring (number) = binarystring (number div 2) + LSC
where by "+" I mean concatenate strings and LSC is just the character
described in the
second step.

This is a recursive definition.  It is pretty simple to turn it
into a recursive procedure.
You need to supply methods for determining if the number is odd or even,
and for
dividing it by 2.

Bob Schor
Pascal Enthusiast

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages

Powered by phpBB® Forum Software