Best search algorithm to find condition within a range

Chris Angelico rosuav at
Tue Apr 7 16:34:31 CEST 2015

On Wed, Apr 8, 2015 at 12:26 AM, Dave Angel <davea at> wrote:
> For example, if you want to convert 378 to base 10 (it's binary internally),
> you'd divide by 10 to get 37, remainder 8.  Save the 8, and loop again.
> Divide 37 by 10 and get 3, remainder 7.  Save the 7. Divide again by 10 and
> get 0, remainder 3.  Save the 3
> Now you have '8', '7', '3'   So you reverse the list, and get
>      '3', '7', '8'

Technically, it doesn't matter that it's stored in binary. All that
matters is that it's stored in some way that you can perform division
on. I used to do this kind of thing in assembly language, pushing
digits onto the stack, then popping them off afterward. (It's actually
easier to make a column of numbers right-justified, as you can simply
create a buffer of the right size - assuming you're working with a
machine word and can know the maximum size - and populate it from the
far end.) But yes, this is the standard way to do base conversions.


More information about the Python-list mailing list