A tough question

Jim Little jiml@inconnect.com
Fri, 11 Jun 1999 13:36:06 -0600


Alexander Clouter wrote:
> 
> Jim Little wrote:
> >
> > The challenge is to create an algorithm:
> >
> > input: a string of decimal digits representing an integer
> > outputs: a string of binary digits representing the same integer
> > example: Given '42', return '101010'.
> >
> > The catch: The input string can be arbitrary length.  So you can't just
> > convert the string to a 32-bit (or 64-bit, or 128-bit, etc) integer and
> > read off the bits.
[...]
> combination of (in order) right shifts, bit masks and then a CMP check
> and write out the result to the desired string location.  Come to think
[...]
> want to do it any other way is beyond me) you should divide by base 2
> numbers (2,4,8,16, etc) starting with the largest.  If it is 1 then

People seem to be missing the catch when answering this question.  The
input value is a STRING.  Not a number.  And it may be of arbitrary
length.  So bit-shifting is out of the question, as is standard
arithmetic.  Also, I can't use code libraries... I'm looking for an
algorithm, not code.

Jim

Prism is at http://www.teleport.com/~sphere