<p>I want to shift the contents of an array of bytes by 12-bit to the left.</p>

<p>For example, starting with this array of type <code>uint8_t shift[10]</code>:</p>

<pre><code>{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xBC}
</code></pre>

<p>I'd like to shift it to the left by 12-bits resulting in:</p>

<pre><code>{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAB, 0xC0, 0x00}
</code></pre>

Lets make it the best way to shift
```
N
```
bits in the array of 8 bit integers.
```
```
N            - Total number of bits to shift
F = (N / 8) - Full 8 bit integers shifted
R = (N % 8) - Remaining bits that need to be shifted
```
```
I guess from here you would have to find the most optimal way to make use of this data to move around ints in an array.  Generic algorithms would be to apply the full integer shifts by starting from the right of the array and moving each integer
```
F
```
indexes.  Zero fill the newly empty spaces.  Then finally perform an
```
R
```
bit shift on all of the indexes, again starting from the right.
In the case of shifting
```
0xBC
```
by
```
R
```
bits you can calculate the overflow by doing a bitwise AND, and the shift using the bitshift operator:
```
```
// 0xAB shifted 4 bits is:
(0xAB & 0x0F) >> 4   // is the overflow      (0x0A)
0xAB << 4            // is the shifted value (0xB0)
```
```
Keep in mind that the 4 bits is just a simple mask: 0x0F or just 0b00001111.  This is easy to calculate, dynamically build, or you can even use a simple static lookup table.
I hope that is generic enough.  I'm not good with C/C++ at all so maybe someone can clean up my syntax or be more specific.
Bonus:  If you're crafty with your C you might be able to fudge multiple array indexes into a single 16, 32, or even 64 bit integer and perform the shifts.  But that is prabably not very portable and I would recommend against this.  Just a possible optimization.