title: Accessing 8-bit data as 7-bit
body: <p>I have an array of 100 <code>uint8_t</code>'s, which is to be treated as a stream of 800 bits, and dealt with 7 bits at a time. So in other words, if the first element of the 8-bit array holds <code>0b11001100</code> and the second holds <code>ob11110000</code> then when I come to read it in 7-bit format, the first element of the 7-bit array would be <code>0b1100110</code> and the second would be <code>0b0111100</code> with the remaining 2 bits being held in the 3rd.
  The first thing I tried was a union...</p>
  
  <pre><code>struct uint7_t {
      uint8_t i1:7;
  };
  
  union uint7_8_t {
      uint8_t u8[100];
      uint7_t u7[115];
  };
  </code></pre>
  
  <p>but of course everything's byte aligned and I essentially end up simply loosing the 8th bit of each element.</p>
  
  <p>Does anyone have any idea's on how I can go about doing this?</p>
  
  <p>Just to be clear, this is something of a visual representation of the result of the union:</p>
  
  <p><code>xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx</code> 32 bits of 8 bit data<br>
  <code>0xxxxxxx 0xxxxxxx 0xxxxxxx 0xxxxxxx</code> 32 bits of 7-bit data.</p>
  
  <p>And this represents what it is that I want to do instead:</p>
  
  <p><code>xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx</code> 32 bits of 8 bit data<br>
  <code>xxxxxxx xxxxxxx xxxxxxx xxxxxxx xxxx</code> 32 bits of 7-bit data.</p>
  
  <p>I'm aware the last bits may be padded but that's fine, I just want someway of accessing each byte 7 bits at a time without losing any of the 800 bits. So far the only way I can think of is lots of bit shifting, which of course would work but I'm sure there's a cleaner way of going about it(?)</p>
  
  <p>Thanks in advance for any answers.</p>