python: convert variable into listo of bytes 
>>> hex_str = "0xffff"
>>> list(struct.pack('!I', int(hex_str, 16)))
['\x00', '\x00', '\xff', '\xff']
>>> list(struct.pack('I', int(hex_str, 16)))
['\xff', '\xff', '\x00', '\x00']


list(bytearray(struct.pack('!I', int(hex_str, 16))))


>>> list(bytearray(struct.pack('!I', 65534)))
[0, 0, 255, 254]


>>> list(bytearray(struct.pack('!H', 65534)))
[255, 254]



x pad byte no value
c char string of length 1 1
b signed char integer 1 (3)
B unsigned char integer 1 (3)
? _Bool bool 1 (1)
h short integer 2 (3)
H unsigned short integer 2 (3)
i int integer 4 (3)
I unsigned int integer 4 (3)
l long integer 4 (3)
L unsigned long integer 4 (3)
q long long integer 8 (2), (3)
Q unsigned long long integer 8 (2), (3)
f float float 4 (4)
d double float 8 (4)
s char[] string
p char[] string
P void * integer (5), (3)


[ add comment ]   |  [ 0 trackbacks ]   |  permalink

<<First <Back | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Next> Last>>