Convert 3 Successive bytes to two int
<p>I am familiar in converting two successive bytes into on int 1:</p>

<p>The format I want is in Little Endian </p>

<pre><code>int number= ((int)BYTE2&lt;&lt;8) | ((int)BYTE1);
</code></pre>

<p>Now I set up the camera to send me the data in 12packed format. This means that to get one byte I need to have the first byte whole and I need only 4 bits from the second byte.</p>

<p>As a result every 3 bytes I can have two 12bit int numbers:</p>

<p>I need to get the first Byte whole and the first 4 bits form the second Byte and combine these 12 bits into an int with little endian format.</p>

<p>Then I need to take the last 4bits from the seond Byte and the whole third Byte and combine them in little endian order to get the second int. See the attached picture.</p>

<p><a href="https://i.stack.imgur.com/QqJBz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QqJBz.jpg" alt="enter image description here"></a></p>

<p>How can I use the bit shift operations to achieve this?</p>

<p>Sorry but I am not familiar with bit shifting operations</p>

<p>I doubt this is the correct way but is this at least the correct approach?</p>

<pre><code>int FirstInt= ((int)(BYTE2 &amp; 0xF0)&lt;&lt;8) | ((int)BYTE1);
int SecondInt= ((int)BYTE3&lt;&lt;8) | ((int)(BYTE2 &amp; 0x0F));
</code></pre>