I want to convert any value (that can be negative or positive) into hex. My current method does this.
The read value in this example is 4003.
workingline
You want the struct module:
struct
>>> struct.pack("<I", 4003).encode('hex') 'a30f0000'
For -2, you'll need to do some other work:
>>> struct.pack("<I", -2 + 2**32).encode('hex') 'feffffff'
A way to do it for any value is:
struct.pack("<I", (value + 2**32) % 2**32).encode('hex')