Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试在 python 中增加以字符串表示的十六进制值,'84B8042100FE'我怎样才能用 1 来增加这个值'84B8042100FF'?
'84B8042100FE'
'84B8042100FF'
谢谢你。
>>> s = '84B8042100FE' >>> num = int(s, 16) + 1 >>> hex(num)[2:].upper() '84B8042100FF'
我总是忘记更好的方法 - 谢谢@Martijn Pieters
>>> '{:X}'.format(num) '84B8042100FF'
In [15]: '{:X}'.format(int('84B8042100FE', 16)+1) Out[15]: '84B8042100FF'