I am new to python and have following problem: I need to convert an integer to a hex string with 6 bytes.
e.g. 281473900746245 --> "\xFF\xFF\xBF\xDE\x16\x05"
The format of the hex-string is important. The length of the int value is variable.
The format '0xffffbf949309L' don't work for me. (I get this with hex(int-value))
My final solution (after some "playing") is:
def _tohex(self, int_value):
data_ = format(int_value, 'x')
result = data_.rjust(12, '0')
hexed = unhexlify(result)
return hexed
Thank you for all the help!
"\xFF\xFF\xBF\xDE\x16\x05"or the string of length 24 given by"\\xFF\\xFF\\xBF\\xDE\\x16\\x05"?