Bit order in bit streams
Is there a 开发者_StackOverflowpreferred order to the bits in a bit stream (where a bit stream is somewhat analogous to Java's Input/OutputStream, but provides bit-level granularity)?
I've read that the output of the Huffman stage of the DEFLATE algorithm considers the least-significant bit (lsb) of a byte to come "before" the most-significant bit (msb), for the purposes of encoding non-byte-aligned values. Is there a reason for choosing lsb-to-msb ordering as opposed to msb-to-lsb ordering? For instance, does this somehow allow for slightly simpler / faster decoding (or encoding) code?
I assume that an "InputBitStream" class in Java would provide some basic operations:
class InputBitStream {
// Optimized for reading a SINGLE bit.
public int readSingleBit() {...}
// Optimized for reading large segments of bits,
// not just readSingleBit() -> put in result -> repeat,
// but if possible, shifting in a byte at a time.
public int readMultipleBits(int count) {...}
}
DEFLATE bit packing: http://www.gzip.org/zlib/rfc-deflate.html#packing
No, there is no standard order. It varies depending on the interface in question.
精彩评论