C++ "Cannot appear in a constant expression", I need this to be a variable, why won't it let me?
<pre><code>string convert_binary_to_hex(string binary_value, int number_of_bits)
{
    bitset&lt;number_of_bits&gt; set(binary_value);   
    ostringstream result;
    result &lt;&lt; hex &lt;&lt; set.to_ulong() &lt;&lt; endl;
    return result.str();
}
</code></pre>

<p>So, in the above method, I am converting binary strings to hex strings. Since hex values are 4 bits, the number_of_bits variable needs to be a multiple of 4... because the binary_value could range anywhere from 4 bits to 256 bits with the application I'm writing. </p>

<p>So... How do I get bitset to take a variable size?</p>

<p>my imports: </p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;bitset&gt;
#include &lt;sstream&gt;
</code></pre>
