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