Best search algorithm to find condition within a range

Denis McMahon denismfmcmahon at gmail.com
Wed Apr 8 13:27:11 EDT 2015


On Tue, 07 Apr 2015 23:18:14 -0700, wxjmfauth wrote:

> Le mercredi 8 avril 2015 08:08:04 UTC+2, wxjm... at gmail.com a écrit :
>> Le mercredi 8 avril 2015 00:57:27 UTC+2, Steven D'Aprano a écrit :
>> > On Tue, 7 Apr 2015 07:44 pm, jonas.thornvall at gmail.com wrote:
>> > 
>> > 
>> > > I want todo faster baseconversion for very big bases like base 1
>> > > 000 000,
>> > > so instead of adding up digits i search it.
>> > 
>> > What digits would you use for base one-million?
>> > 
>> > Base 2 uses 0 1.
>> > Base 3 uses 0 1 2.
>> > Base 10 uses 0 1 2 3 4 5 6 7 8 9.
>> > Base 16 uses 0 1 2 3 4 5 6 7 8 9 A B C D E F.
>> > 
>> > Base one million uses what?
>> > 
>> > How would you write down 12345 in base one-million?
>> > 
>> > 
>> =========
>> 
>> Why should a "digit" contain a single/unique character?
>> 
>> Representation of the number 257 in base 256:
>> 
>> 257 (base 10) --> FF 02 (base 256)
> 
> ======
> 
> Oops, typo, erratum
> 
> *** 257 (base 10) --> 01 01 (base 256) ***

Bzzzzttttt. Wrong.

0101(256) is 0 * 256^3 + 1 * 256^2 + 0 * 256^1 + 1 * 256^0

= 65537

The whole point of "base x" is that any number in the range 0 .. x^1 is 
represented with a single characterisation, otherwise you don't have 
"base x".

This is the same fundamental issue as the OP is failing to understand - 
base x notation is a human readability and representation thing, not an 
inherent feature of numbers.

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list