32 bit int shifted by an amount not in the range
<p>I know there is a missing cast to long, but is there a better way to do this which is less confusing than the shown approch. </p>

<pre><code>static long getLong(byte[] sourceBytes, int sourceBytesIndex, int numOfBytesToConvert)
{
    long longValue = 0;

    longValue = (sourceBytes[sourceBytesIndex] &amp; 0xFF) +
                         ((sourceBytes[sourceBytesIndex + 1] &amp; 0xFF) &lt;&lt; 8);

    if (numOfBytesToConvert &gt; 2)
    {
        longValue += ((sourceBytes[sourceBytesIndex + 2] &amp; 0xFF) &lt;&lt; 16) +
                                ((sourceBytes[sourceBytesIndex + 3] &amp; 0xFF) &lt;&lt; 24);

        if (numOfBytesToConvert &gt; 4)
        {
            longValue += ((sourceBytes[sourceBytesIndex + 4] &amp; 0xFF) &lt;&lt; 32) +
                                    ((sourceBytes[sourceBytesIndex + 5] &amp; 0xFF) &lt;&lt; 40);

            if (numOfBytesToConvert &gt; 6)
            {
                longValue += ((sourceBytes[sourceBytesIndex + 6] &amp; 0xFF) &lt;&lt; 48) +
                                        ((sourceBytes[sourceBytesIndex + 7] &amp; 0xFF) &lt;&lt; 56);
            }
        }
    }

    return longValue;
}
</code></pre>
