A value is not its byte sequence
Endianness specifies how a multi-byte value maps to a sequence of bytes in increasing address order. Little-endian representation places the least significant byte at the lowest address, while big-endian representation places the most significant byte there. The mathematical value and the meaning of arithmetic do not change. What changes is the mapping between that value and its byte representation. If a reader interprets a fixed byte sequence with a different rule from the writer, the reconstructed integer can differ even when every byte was transmitted without corruption.
Tracing a four-byte value
Take the 32-bit value 0x12345678. Its bytes in increasing address order are 12 34 56 78 in big-endian representation and 78 56 34 12 in little-endian representation. Each pair here denotes one hexadecimal byte, not one decimal digit. A hex dump displays bytes in some address order, whereas source-code integer notation displays significance conventionally. Keeping those two views separate prevents a common debugging mistake. Reading only part of the sequence as a smaller integer also requires a defined byte-order interpretation.
| Representation | Bytes in increasing address order |
|---|---|
| Big-endian | 12 34 56 78 |
| Little-endian | 78 56 34 12 |
The format decides at a boundary
A protocol or file format defines the byte order of its numeric fields independently of the host processor. Decode those fields according to the format, using an appropriate conversion routine or explicit construction from bytes. Reinterpreting arbitrary packet bytes as a native structure is not a general solution: alignment, padding, field widths, and object-representation rules can also differ. A useful parser treats the external format as a contract and checks input length before reading. Correct byte order does not make an otherwise truncated or invalid record safe to consume.
Byte order is not bit order or alignment
Byte order should be distinguished from the order in which bits are transmitted on a physical link and from address-alignment requirements. It also does not justify reversing an arbitrary text string. Text encodings have their own rules for code units and byte sequences, and some multi-byte code-unit formats specify endianness explicitly. When investigating a binary-format mismatch, examine field width, byte order, signedness, alignment, and text encoding separately. Changing one of these assumptions can repair one field while leaving a different representation error untouched.