hash() yields different results for different platforms
Grant Edwards
grante at visi.com
Wed Jul 12 10:08:58 EDT 2006
On 2006-07-12, Qiangning Hong <hongqn at gmail.com> wrote:
> Grant Edwards wrote:
>> On 2006-07-11, Qiangning Hong <hongqn at gmail.com> wrote:
>> > However, when I come to Python's builtin hash() function, I
>> > found it produces different values in my two computers! In a
>> > pentium4, hash('a') -> -468864544; in a amd64, hash('a') ->
>> > 12416037344. Does hash function depend on machine's word
>> > length?
>>
>> Apparently. :)
>>
>> The low 32 bits match, so perhaps you should just use that
>> portion of the returned hash?
>>
>> >>> hex(12416037344)
>> '0x2E40DB1E0L'
>> >>> hex(-468864544 & 0xffffffffffffffff)
>> '0xFFFFFFFFE40DB1E0L'
>>
>> >>> hex(12416037344 & 0xffffffff)
>> '0xE40DB1E0L'
>> >>> hex(-468864544 & 0xffffffff)
>> '0xE40DB1E0L'
>
> Is this relationship (same low 32 bits) guaranteed?
No, I don't believe so.
> Will it change in the future version?
It may.
--
Grant Edwards grante Yow! Is this an out-take
at from the "BRADY BUNCH"?
visi.com
More information about the Python-list
mailing list