Datatype size for number of bits
<p>So I have the following function:</p>

<pre><code>static int calcDTSize( int depth )
{
    if ( depth &lt;= 8 )
    {
        return 1;
    }
    if ( depth &lt;= 16 )
    {
        return 2;
    }
    if ( depth &lt;= 32 )
    {
        return 4;
    }
    if ( depth &lt;= 64 )
    {
        return 8;
    }

    throw std::exception( "Invalid bit count" );
}
</code></pre>

<p>Which calculates the size of datatype required for the specified number of bits. Originally I just had:</p>

<pre><code>return ( (int) std::ceil( (double) depth / 8.0 ) );
</code></pre>

<p>However, on most machines that I know of, there isn't a datatype which is 3 bytes long.</p>

<p>I'm sure there must be a neater way of doing the calculation without the if statements but I can't think how.</p>

<p>Anyone got a better solution?</p>
