Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesSenior Deep-DivesModule 3 · Metaclasses, Descriptors, Magicstruct module for binary parsingpredict33 / 161
+100 XP
Task
📝 **Question:** Predict the exact output. Format string \`"<iHB"\` packs an int32, uint16, uint8 as **little-endian**. After packing, the same bytes are unpacked twice — first with the same little-endian format, then with **big-endian** (\`">iHB"\`). What do you see? 📋 Pick the right answer. 💡 **Hint:** Re-read the theory above if unsure.
Predict the output

Read the code carefully

import struct


data = struct.pack("<iHB", 42, 1000, 7)
print(f"size:{len(data)}")
print(f"hex:{data.hex()}")

a, b, c = struct.unpack("<iHB", data)
print(f"unpack:{a},{b},{c}")

flipped = struct.unpack(">iHB", data)
print(f"big_endian:{flipped[0]},{flipped[1]},{flipped[2]}")

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…