This is the function I'm after: -
http://docs.python.org/3/library/stdtypes.html#int.to_bytes
I need big endianness support.
Based on the answer from @nneonneo, here is a function that emulates the to_bytes API:
def to_bytes(n, length, endianess='big'):
h = '%x' % n
s = ('0'*(len(h) % 2) + h).zfill(length*2).decode('hex')
return s if endianess == 'big' else s[::-1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With