Fill 4 bytes little endian with python

Viewed 380

How can I convert number to 4 bytes little endian with python?

For example : 1 -> 01000000 and 258 -> 02010000

1 Answers

Try with struct, 'this module performs conversions between Python values and C structs represented as Python strings':

import struct
print(struct.pack('<i', 258))

where < mean little-endian and i that the element to be pack is an integer

Output:

b'\x02\x01\x00\x00'
Related