Bit order

From Just Solve the File Format Problem
Jump to: navigation, search
File Format
Name Bit order
Ontology

Bit order is the question of whether the most significant bit, or the least significant bit, of a byte comes "first". For many formats, this is not a meaningful question to ask, but for some it is very important.

Disambiguation

There is an orthogonal concept called bit numbering, which is the question of whether the most significant bit, or the least significant bit, is known as "bit 0". This can confuse the issue, since you still have to decide whether "bit 0" or "bit 7" comes first.

The term bit endianness (or bit-level endianness) is sometimes seen, but it seems that not everyone agrees on its meaning, due to conflation of the bit ordering and bit numbering concepts.

Discussion

There are two sensible bit orders, which we can call MSB-first (most significant bit first), and LSB-first (least significant bit first).

Bit order issues are similar to those of (byte) endianness, but with a conceptual difference. With endianness, the storage device (or other data source) assigns a natural order to the bytes, and the format specification decides which bytes are more significant. With bits, it's usually the other way round: The storage device assigns a natural significance to the bits (by packing them into bytes), and the format specification decides their logical order.

Bit order is relevant when data is interpreted as a bitstream, and two or more entities (or portions of entities) are encoded by a single byte. For example, it is often relevant to:

  • Uncompressed bitmap image formats, if multiple pixel are packed into each byte.
  • Some compressed data formats, such as Huffman coding and most forms of LZW.
  • Transfer encodings such as Base64.

Image formats usually use MSB-first order. That usually means the most significant bit(s) of a byte correspond to the leftmost pixel of those encoded by that byte.

Serial communications devices usually use LSB-first order, and this may be reflected in formats related to them, such as fax formats.

Note that if a format uses byte-oriented data compression, it is possible for there to be two distinct layers of bit ordering. For example, an image format could use one bit order for extracting compression codes from the compressed datastream, and another for extracting pixels from the resulting uncompressed datastream.

Links

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox