How does endianness (byte order) affect unpacking 12-bit data?
General knowledgeIn depthAsked by Anonymous23 Oct 2026, 4:55 AM ISTUpdated
In one line
Endianness (byte order) decides how you read and split bytes when unpacking 12-bit data from memory.
Endianness — Order of bytes in a computer word Diagram from Wikipedia showing big-endian and little-endian byte order. Image: Wikipedia
The rule
Endianness is the order in which bytes are stored and read in memory—big-endian stores the most significant byte first, little-endian stores the least significant byte first.
There is no single formula, but the key is:
In big-endian: higher-value bytes come first.
In little-endian: lower-value bytes come first.
Let's understand it simply
Imagine you have a long number, like a phone number, and you write it on two slips of paper. If you give the first slip to your friend, do they expect the start of the number or the end? That’s endianness.
Now, think about a 12-bit number (like 1011 1100 1101). Computers store data in 8-bit chunks (bytes). But 12 bits don’t fit neatly into 8 bits, so the number is split across bytes. The order in which these bytes are stored and read depends on endianness.
Big-endian vs Little-endian (12-bit unpacking)
Big-endian
Little-endian
First byte
Higher bits
Lower bits
Second byte
Lower bits
Higher bits
Example order
[0xAB, 0xCD, 0xEF]
[0xCD, 0xAB, 0xEF]
How it works
Packing 12-bit data:
You have a stream of 12-bit numbers (like sensor readings).
Each 12-bit value must be split across bytes (since 1 byte = 8 bits).
Storing in memory:
The bytes are stored in a certain order: big-endian or little-endian.
Unpacking (reading) the data:
You read the bytes from memory.
You must know the endianness to combine the right bits from each byte.
Big-endian unpacking:
The first byte you read contains the higher bits of the 12-bit value.
The next byte gives the lower bits.
Little-endian unpacking:
The first byte gives the lower bits.
The next byte gives the higher bits.
If you get the order wrong:
You combine the wrong bits, and the value becomes garbage.
Unpacking 12-bit data (big-endian)
Read first byte (higher 8 bits)
Read next 4 bits from second byte (lower 4 bits)
Combine to get first 12-bit value
Read last 4 bits of second byte (higher 4 bits of next value)
Read next byte (lower 8 bits)
Combine to get second 12-bit value
The story behind it
The idea of endianness comes from computer architecture. Different processors (like Intel and ARM) chose different byte orders for historical reasons. The term "endianness" was inspired by a story in Jonathan Swift’s "Gulliver’s Travels" about people fighting over which end of an egg to break. In computers, it’s about which end of the data you read first.
Where you see it in real life
Reading sensor data:
Many sensors (like temperature or ECG) send 12-bit values. If you unpack them with the wrong endianness, your readings are wrong.
Image files:
Some image formats use 12-bit pixels. Software must know the byte order to display the image correctly.
Networking:
Data sent over the internet often uses big-endian. If your computer is little-endian, you must swap the bytes.
Embedded systems:
Microcontrollers in cars or washing machines may use 12-bit data and have a fixed endianness.
Audio files:
Some audio formats use 12-bit samples. Playing them with the wrong byte order makes the sound noisy.
Medical equipment:
Devices like ECG machines store patient data in 12-bit chunks. Wrong unpacking can lead to wrong diagnosis.
Why it matters
Correct data interpretation:
If you use the wrong endianness, your numbers are wrong—like reading a cricket score backwards.
Software compatibility:
Programs must handle endianness to work across different computers.
Data sharing:
When sharing files between systems, you must agree on endianness.
Exams and interviews:
Questions on endianness are common in computer science exams and job interviews.
Worked example
Let’s say you have two 12-bit numbers packed into three bytes: