a985b4593d
These two are apprerently the most concise and efficient way to convert int to/from bytes in Python. The alternatives are struct and array modules, but methods using them are more verbose in Python code and less efficient in memory/cycles.
7 lines
277 B
Python
7 lines
277 B
Python
print((10).to_bytes(1, "little"))
|
|
print((111111).to_bytes(4, "little"))
|
|
print((100).to_bytes(10, "little"))
|
|
print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little"))
|
|
print(int.from_bytes(b"\x01\0\0\0\0\0\0\0", "little"))
|
|
print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little"))
|