If I have a string with the following value:
STR = "00DE"
how do I convert that so that STR
becomes 0x00DE
? What function do I use?
If you mean you want STR to be a string in the form you describe, the simplest way is to prepend '0x'
to the string:
STR = '0x' + STR
If you mean that you want STR to become an integer with the indicated numeric value, then invoke the int()
constructor:
STR = int(STR, 16)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.