2017年11月28日 星期二

[Python] HEX轉換


Without the 0x prefix, you need to specify the base explicitly, otherwise there's no way to tell:
x = int("deadbeef", 16)
With the 0x prefix, Python can distinguish hex and decimal automatically.
>>> print int("0xdeadbeef", 0)
3735928559
>>> print int("10", 0)
10

https://stackoverflow.com/questions/209513/convert-hex-string-to-int-in-python

沒有留言: