I have raw hex from a com port that I want to represent as a hex value that I can use later for bitwise operations.
For example, I have 1035 and I want it as 0x1035.
I am relatively certain the hex() function is not what I want. This converts int(1035) into hex 40B.
I have tried concatenating a '0x' to my value, the problem I found with this is it is then type str, which I can't do bitwise &,|, etc. Converting it to int results in: invalid literal for int() with base 10: '0x1035'
I have tried converting the hex to binary, with the same problem as before with type str and not type int.
Life becomes way easier when I define, hex = 0x1035, for example. But I want this to be reusable for many messages from the com port.
How do I convert a string '0x1035' to a hex int? Or, how do I tell the interpreter that the int I have, 1035, I want interpreted as hex, 0x1035?