1

Possible Duplicate:
how to parse hex or decimal int in Python

i have a bunch of Hexadecimal colors in a database stored as strings.

e.g. '0xFFFF00'

when i get them from the database i need to convert this string into an actual hexadecimal number, so

0xFFFF00

how can i do this in python

Community
  • 1
  • 1
JiminyCricket
  • 6,632
  • 7
  • 41
  • 58

3 Answers3

5

This is one way to do it:

>>> s = '0xFFFF00'
>>> i = int(s, 16)
>>> print i
Mark Byers
  • 767,688
  • 176
  • 1,542
  • 1,434
0

hex(int('0xFFFF00', 16))

leoluk
  • 11,759
  • 6
  • 41
  • 49
0

Also this works

number = int('0xFFFF00',0)
print("%x follows %x" % (number+1, number))

0 argument tells interpreter to follow the Python rules of numbers to decide the used format of number so this expression will work right for all numbers.

Tony Veijalainen
  • 5,279
  • 21
  • 31