I am trying to convert an integer number into an array of byte strings.
def int2Hex():
hex = '%08x' % 32
bytes = []
for i in range(0,4):
bytes.append('0x' + hex[i*2: i*2 + 2])
return bytes[::-1] #return in little endian
The above code works for positive numbers: ['0x00', '0x00', '0x00', '0x20']
but when I use a negative number I'll get something like this: ['0x-0', '0x00', '0x00', '0x20']
What I want for negative numbers is the 2's complement bytes. I am using python 2.