I have a bunch of hex as strings.
str = "e79" # 0xe79
str2 = "1533a" # 0x1533a
etc...
What's the best way to do some addition on these? For example, if I have str = "e79" and I want to add the decimal 37 to it to get str = "e9e"
I have a bunch of hex as strings.
str = "e79" # 0xe79
str2 = "1533a" # 0x1533a
etc...
What's the best way to do some addition on these? For example, if I have str = "e79" and I want to add the decimal 37 to it to get str = "e9e"
You'll have to parse the values into integers if you want to do integer arithmetic; use int(hexstring, 16)
.
You can always convert back to the hex string representation using format()
:
result = format(int(strvalue, 16) + 37, 'x')
result = hex(int(str, 16) + int(str2, 16))