How can I convert an arbitrary length (positive) integer into a bytes object in Python 3? The most significant byte should be first so that it is basically a base 256 encoding.
For fixed length values (up to unsigned long long) you can use the struct module but there seems to be no library support for conversions of large numbers in Python.
Expected results:
>>> intToBytes(5)
b'\x05'
>>> intToBytes(256)
b'\x01\x00'
>>> intToBytes(6444498374093663777)
b'You won!'