문제

Is there a preferred 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top