val1 = hex(100)
val2 = hex(50)
val3 = hex(int(val1, 16) - int(val2, 16))
hex_str = str(val1) + str(val2) + str(val3)
print(hex_str)
In the above example, my end goal is to have a string that looks like this: 643232
Currently however the result I am getting has the string as 0x640x320x32
Is there a way in Python to remove the 0x
from the beginning of a hex string?
Or will I have to remove it using a regular expression with something like re.sub()
?
EDIT: I also need to make sure I am always getting too characters. So for example if I was looking for the hex value of 5 I'd get 05
try:
val1 = hex(100)[2:]
val2 = hex(50)[2:]
val3 = hex(int(val1, 16) - int(val2, 16))[2:]
hex_str = str(val1) + str(val2) + str(val3)
print(hex_str)
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