printing longs

John Machin sjmachin at lexicon.net
Sat Apr 7 00:19:25 CEST 2007


On Apr 7, 7:54 am, "garyp" <gary.por... at authentec.com> wrote:
> Python 2.3.4 (#1, Oct 26 2004, 16:42:40)
> [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
>
> >>> x = int("80000000", 16)
> >>> x = x | 0x80000000
>
> <stdin>:1: FutureWarning: hex/oct constants > sys.maxint will return
> positive values in Python 2.4 and up

As your subject says, you are working with longs, so don't mix in an
int (0x8000000, which is negative in Python 2.3 and earlier) -- use
0x8000000L instead.

>
> >>> print "%x" % ( x )
> -80000000

"%x" % x
is enough.

>
> How do I get python to print the usual answer: 8000000, not -80000000

"usual" in what context?

Cheers,
John




More information about the Python-list mailing list