Weird 'and' result...

Peter Hansen peter at engcorp.com
Sat Jun 21 01:52:17 CEST 2003


"Artur M. Piwko" wrote:
> 
> pipen at demon:/tmp/ekg-1.1rc1$ python
> Python 2.2.3 (#1, Jun  4 2003, 02:54:59)
> [GCC 3.3 (Debian)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> "%08x" % (0xea7ee5ccea7 & 0xffffffff)
> 'ea7ee5ccea7'
> >>>
> 
> And it should be 'ee5ccea7'. Am I missing something?

I don't know the details, since the first value won't fit
in an int, it's quietly making it a long, then treating the
second value as "-1" and/or basically sign-extending it
to an appropriate size to do the AND for you...

Change it to 0xffffffffL (note the L) and it works "better".

A guru will be along shortly to explain the details. :-)

-Peter




More information about the Python-list mailing list