开发者

Bits stream reading order

I've read in manual:

For bit-oriented delivery, the bit order for the byte stream format is specified to start with the MSB of the first byte, proceed to the LSB of the first byte, followed by the MSB of the sec开发者_StackOverflow中文版ond byte, etc.

In my application I have to cope with bits. (for example I have decimal number 5, in binary format it looks like 00000101) So, is that means (according to manual) that order of bits I read is

<= 0 <= 0 <= 0 <= 0 <= 0 <= 1 <= 0 <= 1 (first read bit I read is 0, second is 0 etc....)

or it means such order of reading bits:

<= 1 <= 0 <= 1 <= 0 <= 0 <= 0 <= 0 <= 0 (first read bit I read is 1, second is 0 etc....)

Thanks


  • MSB: Most significant bit
  • LSB: Least significant bit

So for 5 (0000_0101) the bit on the left (representing 27) is "most significant" and the bit on the right (representing 20) is the "least significant". Therefore, yes, expect 0 to be the first bit.


In Java, the default methods for reading and writing streams of bytes will automatically default to network byte-order, so you're probably good to go.


If the first bytes in your stream are 0x7D,0x01, then the stream of bits begins 0,1,1,1,1,1,0,1,0,0,0,0,0,0,0,1.


Byte order is mostly referred to as endian-ness. You have big-endian systems and little-endian systems.

Big endian you have the Most Significant Bit first and in Little Endian, the least significant bit is first.

Most network traffic is big endian. A X86 machine is always little-endian.

Here is more info about endian-ness

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜