How to create long string of bytes in big-endian format

249 Views Asked by At

I'm trying to create a 16 bytes string on the wire in Big-Endian format. As you can see I'm ending-up with Little-Endian; where prepended 0's are at the end.

>>> import struct
>>> auth = "{0:<16}".format(1437722681) 
>>> authenticator = struct.pack("16s",bytes(auth,"utf-8")) 
>>> print (authenticator)
b'1437722681      '

I would like to create a code where I can have prepended values at the beginning, something like below:

>>> print (authenticator)
b'      1437722681'
1

There are 1 best solutions below

0
On BEST ANSWER

it seems that change of the following line did the trick.

"{0:>16}.format(...)