title: Java DataStream alignment
body: <p>I have to do the following exercise. Can someone please explain why the 3 bits in the example are misaligned? </p>
  
  <pre><code>/*
   * A data stream contains a binary stream of data in little endian byte format.
   *
   * The binary data can be mis-aligned to byte boundaries.
   * In order to indicate alignment to the consumer, a periodic alignment 
   * synchronisation sequence is output.
   * The alignment sequence is defined as 4 bytes of 0x00 followed by a byte of 0x80.
   *
   * For example, the following stream is mis-aligned by 3 bits and has an alignment sequence followed by 
   * the byte values 0x01,0x02,0x03
   *
   * 0x65, 0x50, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x10, 0x18
   *
   * The sequence ends when there's not enough bits left to fill a byte
   *
   */
  </code></pre>
  
  <p>Moreover, this is the interface that has to be implemented</p>
  
  <pre><code> interface RawDataStream{
  
  /*
   * Reads raw data from a stream
   *
   * @param buffer to store read bytes in
   * @param num_bytes number of bytes to read from the stream into the buffer
   * 
   * @return number of bytes read from stream into buffer
   *        -1 no data in stream
   *        -2 End of stream
   */
  
   int readBytes(char[] buffer, int num_bytes);
   }
  </code></pre>
  
  <p>What is the best way to verify the alignment sequence?</p>