Exercise 2 solution import os, tempfile values = [1, 256, 65535, 1000] path = os.path.join(tempfile.gettempdir(), "u16.bin") with open(path, "wb") as f: for v in values: f.write(v.to_bytes(2, "little")) with open(path, "rb") as f: raw = f.read() print(raw.hex(" ")) # 01 00 00 01 ff ff e8 03 little = [int.from_bytes(raw[i:i + 2], "little") for i in range(0, len(raw), 2)] big = [int.from_bytes(raw[i:i + 2], "big") for i in range(0, len(raw), 2)] print(little) # [1, 256, 65535, 1000] print(big) # [256, 1, 65535, 59395] print(little == values) # True os.remove(path) (Run as written; the output matched the comments.) Explanation: each value takes two bytes, low byte first. 1 is 01 00, 256 is 00 01, and 1000 (0x03e8) is e8 03. Reading the same bytes as big-endian swaps the two bytes of every pair, so 1 becomes 256, 256 becomes 1, and 1000 becomes 0xe803 = 59395. 65535 is ff ff either way, which shows why a wrong byte order can go unnoticed on symmetric values.