I want to convert "0d" to 0xd or "ff" to 0xff.
I have tried hex("0d")
Do base conversion as 16, the second operand to int takes the base value of the number you need to convert
>>> a = "0d"
>>> int(a,16)
13
>>> hex(int(a,16))
'0xd'
>>> a = "ff"
>>> int(a,16)
255
>>> hex(int(a,16))
'0xff'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With