I need to convert int list into a byte string but I don’t know how. I can’t use bytes()
because the values are too large.
JavaScript
x
2
1
bytes([152710136, 76354857, 38177353, 2252736081, 1126368238])
2
I get this error:
JavaScript
1
2
1
ValueError: bytes must be in range(0, 256)
2
The expected value is:
JavaScript
1
2
1
b'xc4xb7x86x17xcd'
2
Advertisement
Answer
You can use .to_bytes
to return an array of bytes representing an integer.
Note: This works only in python 3.1 and above.
For example:
JavaScript
1
3
1
>>> (1024).to_bytes(2, byteorder='big')
2
b'x04x00'
3