hex and long

Alex Martelli aleax at aleax.it
Sat Apr 13 12:00:24 EDT 2002


Robin Becker wrote:
        ...
> Is there an easy way to get back to the low 32 bits of a long or do I
> have to do bit twiddling?

Say
>>> x=23**45

Now, in what category would you range:

>>> x & 2**32-1
2112869559L

>>> x^(x>>32<<32)
2112869559L

>>> x & 0xffffffffL
2112869559L

>>> x & ~(-1L<<32)
2112869559L

To me, they all look BOTH easy AND bit-twiddling (how else than by
twiddling bits are you going to extract a certain string of bits?).


Alex




More information about the Python-list mailing list