Bit order

From Just Solve the File Format Problem
(Difference between revisions)
Jump to: navigation, search
(Created page with "{{FormatInfo |formattype=electronic |subcat=Binary Data }} '''Bit order''' is the question of whether the most significant bit, or the least significant bit, of a byte comes "...")
 
(Removed from deprecated "Binary Data" category)
 
(3 intermediate revisions by one user not shown)
Line 1: Line 1:
 
{{FormatInfo
 
{{FormatInfo
 
|formattype=electronic
 
|formattype=electronic
|subcat=Binary Data
+
|subcat=Elements of File Formats
 
}}
 
}}
 
'''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.
 
'''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.
Line 13: Line 13:
 
There are two sensible bit orders, which we can call '''MSB-first''' (most significant bit first), and '''LSB-first''' (least significant bit first).
 
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, that 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 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:
 
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:
Line 22: Line 22:
 
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.
 
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.
+
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 uncompressed datastream.
+
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 ==
 
== Links ==
 
* [http://www.fileformat.info/mirror/egff/ch06_04.htm Bit Order], from the [[Encyclopedia of Graphics File Formats]]
 
* [http://www.fileformat.info/mirror/egff/ch06_04.htm Bit Order], from the [[Encyclopedia of Graphics File Formats]]
* [[Wikipedia:Endianness|Wikipedia: Endianness]] - Has a section on bit endianness
+
* [[Wikipedia: Endianness]] - Has a section on bit endianness
* [[Wikipedia:Bit numbering|Wikipedia: Bit numbering]]
+
* [[Wikipedia: Bit numbering]]
 
* [http://eli.thegreenplace.net/2005/11/22/when-bit-endianness-matters/ When bit endianness matters]
 
* [http://eli.thegreenplace.net/2005/11/22/when-bit-endianness-matters/ When bit endianness matters]

Latest revision as of 19:30, 23 August 2017

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.

[edit] 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.

[edit] 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.

[edit] Links

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox