How compare hex numbers?

Gustaf Liljegren gustafl at algonet.se
Sat Dec 14 06:41:39 EST 2002


I'm trying to compare one hex number with another to see which is bigger:

U = hex(U)
if U < '0x10000':
  print "U is smaller."
else:
  print "U is bigger."

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?

Gustaf



More information about the Python-list mailing list