How compare hex numbers?
Erik Max Francis
max at alcyone.com
Sat Dec 14 16:22:53 EST 2002
Gustaf Liljegren wrote:
> Python says U is bigger when U is in fact smaller. I've tried other
> ways to
> specify that '0x10000' is hexadecimal too, including:
>
> if U < 0x10000:
> if U < '\x10000':
> if U < hex('0x10000'):
>
> What is the right syntax?
If U is in fact a number, then the first is the proper syntax. The
second is comparing it against a very confused four-character string,
and the third will result in a TypeError (hex is for converting numbers
to a hexadecimal string notation, it doesn't work with strings
themselves).
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ A physicist is an atom's way of knowing about atoms.
\__/ George Wald
Python chess module / http://www.alcyone.com/pyos/chess/
A chess game adjudicator in Python.
More information about the Python-list
mailing list