Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's an easy way to deal with the arithmetic. The following utility function modifies a java BitSet to set bit flags based on the contents of a byte value.</p> <pre><code>static void setByte(BitSet bitSet, int byteNum, byte b) { int base = byteNum * 8; bitSet.set(base + 7, (b &amp; 0x80) != 0); bitSet.set(base + 6, (b &amp; 0x40) != 0); bitSet.set(base + 5, (b &amp; 0x20) != 0); bitSet.set(base + 4, (b &amp; 0x10) != 0); bitSet.set(base + 3, (b &amp; 0x08) != 0); bitSet.set(base + 2, (b &amp; 0x04) != 0); bitSet.set(base + 1, (b &amp; 0x02) != 0); bitSet.set(base + 0, (b &amp; 0x01) != 0); } </code></pre> <p>It takes a "byteNum" parameter, in case you want to have multiple bytes put into the bitset, which in your case you do.</p> <p>byte 0 would be bitset positions 0-7 byte 1 would be bitset positions 8-15 etc....</p> <p>And within each byte, the high order bit is position 7, low order bit position 0.</p> <p>Then you could simply do this once you have the two bytes. I'm assuming that the first byte is the high order bits, (0x0800 - 0x8000), and the second byte is the low order bits (0x0001 - 0x0080), though your spec should tell you that.</p> <pre><code>byte buf[] = new byte[2]; inputStream.read(buf, 0, 2); BitSet bitSet = new BitSet(); // low order byte is the second one setByte(bitSet, 0, bytes[1]); // high order byte is first setByte(bitSet, 1, byte1[0]); boolean archiveVolume = bitSet.get(0); boolean commentPresent = bitSet.get(1); ... boolean firstVolume = bitSet.get(8); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload